-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathrun_after.lua
95 lines (93 loc) · 3.18 KB
/
run_after.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
local constants = require("overseer.constants")
local log = require("overseer.log")
local task_list = require("overseer.task_list")
local util = require("overseer.util")
local STATUS = constants.STATUS
---@type overseer.ComponentFileDefinition
local comp = {
desc = "Run other tasks after this task completes",
params = {
task_names = {
desc = "Names of dependency task templates",
long_desc = 'This can be a list of strings (template names, e.g. {"cargo build"}), tables (name with params, e.g. {"shell", cmd = "sleep 10"}), or tables (raw task params, e.g. {cmd = "sleep 10"})',
-- TODO Can't input dependencies WITH params in the task launcher b/c the type is too complex
type = "list",
},
statuses = {
desc = "Only run successive tasks if the final status is in this list",
type = "list",
default = { STATUS.SUCCESS },
subtype = {
type = "enum",
choices = STATUS.values,
},
},
detach = {
desc = "Tasks created will not be linked to the parent task",
long_desc = "This means they will not restart when the parent restarts, and will not be disposed when the parent is disposed",
type = "boolean",
default = false,
},
},
constructor = function(params)
return {
task_lookup = {},
all_tasks = {},
on_complete = function(self, task)
if not vim.tbl_contains(params.statuses, task.status) then
return
end
for i, name_or_config in ipairs(params.task_names) do
local task_id = self.task_lookup[i]
local after_task = task_id and task_list.get(task_id)
if after_task then
if not after_task:is_pending() then
after_task:reset()
end
after_task:start()
else
util.run_template_or_task(name_or_config, function(new_task)
if not new_task then
log:error(
"Task(%s)[run_after] could not find template %s",
task.name,
name_or_config
)
return
end
new_task.cwd = new_task.cwd or task.cwd
new_task.env = new_task.env or task.env
if not params.detach then
self.task_lookup[i] = new_task.id
table.insert(self.all_tasks, new_task.id)
end
-- Don't include after tasks when saving to bundle.
-- We will re-create them when this task runs again
new_task:set_include_in_bundle(false)
new_task:start()
end)
end
end
end,
on_reset = function(self, task)
for _, task_id in pairs(self.task_lookup) do
local after_task = task_list.get(task_id)
if after_task then
after_task:stop()
after_task:reset()
end
end
end,
on_dispose = function(self, task)
for _, task_id in ipairs(self.all_tasks) do
local after_task = task_list.get(task_id)
if after_task then
after_task:stop()
after_task:dispose()
end
end
end,
}
end,
}
return comp