local workflow = require("assay.workflow")
workflow.connect(env.get("ASSAY_ENGINE_URL") or "http://localhost:8080")
workflow.define("NightlyReport", function(ctx, input)
local report = ctx:side_effect("issue_report_id", function()
return "rep-" .. tostring(os.time()) .. "-" .. tostring(math.random(10000, 99999))
end)
local scan = ctx:execute_activity("scan_anomalies", {
region = input.region,
report_id = report,
})
for i, anomaly in ipairs(scan.anomalies) do
ctx:start_child_workflow("HandleAnomaly", {
workflow_id = report .. "-anomaly-" .. tostring(i),
input = { anomaly = anomaly, report_id = report },
})
end
return {
report_id = report,
region = input.region,
anomalies_handled = #scan.anomalies,
}
end)
workflow.define("HandleAnomaly", function(ctx, input)
local r = ctx:execute_activity("remediate", input)
return { fixed = r.fixed, anomaly = input.anomaly }
end)
workflow.activity("scan_anomalies", function(ctx, input)
return {
region = input.region,
anomalies = {
{ id = "a-1", kind = "stale_lock" },
{ id = "a-2", kind = "missing_index" },
{ id = "a-3", kind = "orphaned_record" },
},
}
end)
workflow.activity("remediate", function(ctx, input)
return { fixed = true, anomaly = input.anomaly }
end)
log.info("nightly-report worker ready — POST a schedule to fire it")
workflow.listen({ queue = "default" })