19
loading...
This website collects cookies to deliver better user experience
(async function workLoop() {
const nextTask = taskQueue.pop()
await logEvent('starting task:', nextTask.ID)
try {
await doWork(nextTask) // this could fail!
catch (err) {
await logEvent('reverting task:', nextTask.ID, err)
taskQueue.push(nextTask)
}
await logEvent('completed task:', nextTask.ID)
setTimeout(workLoop, 0)
})()
eventHistory
:(function workLoop() {
const nextTask = reconcile(eventHistory, workStateMachine)
doWorkAndLogHistory(nextTask, eventHistory) // transactional
setTimeout(workLoop, 0)
})()
reconcile
and doWorkAndLogHistory
. But this solves a lot of problems: [
{
"first_step": {
"call": "http.get",
"args": {
"url": "https://www.example.com/callA"
},
"result": "first_result"
}
},
{
"where_to_jump": {
"switch": [
{
"condition": "${first_result.body.SomeField < 10}",
"next": "small"
},
{
"condition": "${first_result.body.SomeField < 100}",
"next": "medium"
}
],
"next": "large"
}
},
{
"small": {
"call": "http.get",
"args": {
"url": "https://www.example.com/SmallFunc"
},
"next": "end"
}
},
{
"medium": {
"call": "http.get",
"args": {
"url": "https://www.example.com/MediumFunc"
},
"next": "end"
}
},
{
"large": {
"call": "http.get",
"args": {
"url": "https://www.example.com/LargeFunc"
},
"next": "end"
}
}
]
async function dataPipeline() {
const { body: SomeField } = await httpGet("https://www.example.com/callA")
if (SomeField < 10) {
await httpGet("https://www.example.com/SmallFunc")
} else if (SomeField < 100) {
await httpGet("https://www.example.com/MediumFunc")
} else {
await httpGet("https://www.example.com/BigFunc")
}
}
19