-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathon_complete_restart.lua
47 lines (45 loc) · 1.17 KB
/
on_complete_restart.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
local constants = require("overseer.constants")
local util = require("overseer.util")
local STATUS = constants.STATUS
---@type overseer.ComponentFileDefinition
local comp = {
desc = "Restart task when it completes",
params = {
statuses = {
desc = "What statuses will trigger a restart",
type = "list",
default = { STATUS.FAILURE },
subtype = {
type = "enum",
choices = STATUS.values,
},
},
delay = {
desc = "How long to wait (in ms) post-result before triggering restart",
default = 500,
type = "number",
validate = function(v)
return v > 0
end,
},
},
constructor = function(opts)
if type(opts.statuses) == "string" then
opts.statuses = { opts.statuses }
end
local lookup = util.list_to_map(opts.statuses)
return {
on_complete = function(self, task, status)
if lookup[status] then
vim.defer_fn(function()
-- Only continue with the restart if the status hasn't changed
if task.status == status then
task:restart()
end
end, opts.delay)
end
end,
}
end,
}
return comp