-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathdependencies.lua
More file actions
101 lines (100 loc) · 3.49 KB
/
dependencies.lua
File metadata and controls
101 lines (100 loc) · 3.49 KB
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
96
97
98
99
100
101
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
return {
desc = "Set dependencies for task",
params = {
tasks = {
desc = "Names of dependency task templates",
long_desc = 'This can be a list of strings (template names, e.g. "cargo build"), tables (template name with params, e.g. {"mytask", foo = "bar"}), 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",
optional = true,
},
task_names = {
deprecated = true,
desc = "Names of dependency task templates",
long_desc = 'This can be a list of strings (template names, e.g. "cargo build"), tables (template name with params, e.g. {"mytask", foo = "bar"}), 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",
optional = true,
},
sequential = {
type = "boolean",
default = false,
},
},
constructor = function(params)
return {
task_lookup = {},
on_pre_start = function(self, task)
local started_any = false
for i, name_or_config in ipairs(params.tasks or params.task_names or {}) do
local task_id = self.task_lookup[i]
local dep_task = task_id and task_list.get(task_id)
if not dep_task then
-- If no task ID found, start the dependency
util.run_template_or_task(name_or_config, function(new_task)
if not new_task then
log.error(
"Task(%s)[dependencies] 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
new_task.parent_id = task.parent_id or task.id
self.task_lookup[i] = new_task.id
new_task:add_component({
"dependencies.on_success_complete_dependency",
task_id = task.id,
})
new_task.ephemeral = true
new_task:start()
end)
started_any = true
if params.sequential then
return false
end
else
if dep_task.status == STATUS.PENDING then
dep_task:start()
started_any = true
if params.sequential then
return false
end
elseif dep_task.status ~= STATUS.SUCCESS then
return false
end
end
end
return not started_any
end,
on_reset = function(self, task)
for _, task_id in pairs(self.task_lookup) do
local dep_task = task_list.get(task_id)
if dep_task then
dep_task:reset()
end
end
end,
on_dispose = function(self, task)
for _, task_id in pairs(self.task_lookup) do
local dep_task = task_list.get(task_id)
if dep_task then
dep_task:stop()
dep_task:dispose(true)
end
end
end,
on_dependency_complete = function(self, task)
task:start()
end,
}
end,
}