const dataWorkflow = hy.workflow({
name: 'dataWorkflow',
body: (workflowBuilder) => {
workflowBuilder
.start(fetchDataTask)
.next(processDataTask)
.next(saveResultsTask);
return workflowBuilder;
},
config: {}
});
const fetchDataTask = hy.task({
name: 'fetchData',
func: async () => {
const ctx = getHyrexContext();
const data = await fetchFromAPI();
// Store for next task in workflow
await HyrexKV.set(
`workflow-${ctx.workflowRunId}-data`,
JSON.stringify(data)
);
return { fetched: true };
}
});
const processDataTask = hy.task({
name: 'processData',
func: async () => {
const ctx = getHyrexContext();
// Retrieve data from previous task
const dataStr = await HyrexKV.get(
`workflow-${ctx.workflowRunId}-data`
);
const data = JSON.parse(dataStr);
const processed = transformData(data);
// Store for final task
await HyrexKV.set(
`workflow-${ctx.workflowRunId}-result`,
JSON.stringify(processed)
);
return { processed: true };
}
});