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
-- worker_child.lua
-- Worker child that can be spawned by a parent and executes tasks.
--
-- This is a RunnableChild that:
-- - Has a run() function for task execution
-- - Responds to signals (Veto -> Abort)
-- - Can spawn sub-children via orcs.spawn_child()
-- - Emits output via orcs.emit_output()
return {
id = "worker",
-- run(input) -> { success, data?, error? }
-- Main execution function for the worker
run = function(input)
local task = input.task or "default-task"
local iterations = input.iterations or 1
-- Emit progress
orcs.emit_output("Worker starting task: " .. task)
-- Simulate work
local results = {}
for i = 1, iterations do
table.insert(results, {
iteration = i,
task = task,
result = task .. "-result-" .. i,
})
end
orcs.emit_output("Worker completed " .. iterations .. " iterations")
return {
success = true,
data = {
task = task,
iterations = iterations,
results = results,
}
}
end,
on_signal = function(sig)
if sig.kind == "Veto" then
-- Now we can use emit_output in on_signal (context is registered)
if orcs and orcs.emit_output then
orcs.emit_output("Worker received veto, aborting...", "warn")
elseif orcs and orcs.log then
orcs.log("warn", "Worker received veto, aborting...")
end
return "Abort"
elseif sig.kind == "Cancel" then
return "Handled"
end
return "Ignored"
end,
abort = function()
orcs.emit_output("Worker abort() called", "warn")
end,
}