Skip to content

Commit 6c59574

Browse files
committed
exit codes for error/timeout
1 parent b5de39e commit 6c59574

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/ascend.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@ tasks.add(services.healthcheck())
3434

3535
local end_time = timeout and os.time() + timeout or nil
3636
log_info("ascend started")
37-
tasks.run({ stopOnError = true , end_time = end_time })
37+
local stop_reason = tasks.run({ stopOnError = true , end_time = end_time })
3838

3939
tasks.clear()
4040
tasks.add(services.stop_all())
4141
tasks.run({ ignoreStop = true, stopOnEmpty = true })
4242

4343
log_info("ascend stopped")
44+
45+
if stop_reason == "error" then
46+
os.exit(1)
47+
end
48+
49+
if stop_reason == "timeout" then
50+
os.exit(2)
51+
end

src/ascend/tasks.lua

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,25 @@ function tasks.add(task)
2727
table.insert(taskQueue, task)
2828
end
2929

30+
---@alias StopReason "error" | "empty" | "timeout" | "requested"
31+
3032
--- run all tasks in the task queue
3133
---@param options TaskPoolOptions
34+
---@return StopReason
3235
function tasks.run(options)
3336
if not options then
3437
options = {}
3538
end
3639

37-
while options.ignoreStop or not is_stop_requested() and not timed_out(options.end_time) do
38-
local stop = false
40+
while true do
41+
if not options.ignoreStop and is_stop_requested() then
42+
return "requested"
43+
end
44+
if timed_out(options.end_time) then
45+
return "timeout"
46+
end
47+
48+
local error_occured = false
3949

4050
local newTaskQueue = {}
4151
for _, task in ipairs(taskQueue) do
@@ -46,7 +56,7 @@ function tasks.run(options)
4656
if not ok then
4757
log_error("!!! task failed !!!", { error = err })
4858
if options.stopOnError then
49-
stop = true
59+
error_occured = true
5060
break
5161
end
5262
end
@@ -55,8 +65,11 @@ function tasks.run(options)
5565
end
5666

5767
taskQueue = newTaskQueue
58-
if stop or (options.stopOnEmpty and #taskQueue == 0) then
59-
break
68+
if error_occured then
69+
return "error"
70+
end
71+
if (options.stopOnEmpty and #taskQueue == 0) then
72+
return "empty"
6073
end
6174
os.sleep(100, 1000)
6275
end

src/version-info.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
local ASCEND_VERSION = "0.7.3"
1+
local ASCEND_VERSION = "0.7.4"
22

33
return {
4-
VERSION = ASCEND_VERSION,
4+
VERSION = ASCEND_VERSION
55
}

0 commit comments

Comments
 (0)