3. A progressive process
A progressive process performs one finite run and returns to idle when it
finishes. It fits imports, migrations, report generation, cache rebuilds, and other
work that has a clear end.
Register monthly-report
- Spring Boot
- Node.js
- Raw API
@SynapsysProcess(name = "monthly-report")
public class MonthlyReport extends AbstractProgressiveProcess {
private final ReportService reports;
public MonthlyReport(ReportService reports) {
this.reports = reports;
}
@Override
protected void run() throws Exception {
for (Account account : reports.accounts()) {
checkCancelled();
reports.buildFor(account);
System.out.println("completed " + account.id());
}
}
}
Call checkCancelled() between units of work. Blocking I/O should have its own
timeout so interruption can be observed.
synapsys.progressive('monthly-report', async (ctx) => {
for (const account of accounts) {
ctx.throwIfCancelled();
await buildReport(account, { signal: ctx.signal });
console.log(`completed ${account.id}`);
}
});
Pass ctx.signal to APIs that accept an AbortSignal. A stop then cancels in-flight
I/O instead of waiting for it to finish.
Report the process as progressive. When a newer start token arrives, create one run,
preserve its runId, and report running. Report idle after the body completes.
{
"name": "monthly-report",
"type": "progressive",
"currentState": "idle",
"ackToken": 0,
"runId": null
}
Your client must prevent a duplicate response from starting a second run. Follow the Raw API checklist.
Run and inspect it
- Restart the worker and open Processes.
- Start
monthly-report. - Open Executions and watch the captured progress lines.
- Let the run finish. Its current state returns to
idlewithout a stop command. - Start it again and confirm that Core creates a separate execution.
Cancel a run
Start it once more and choose Stop while it is processing. The worker reports
stopping, reaches its next cancellation point, and returns to idle. If it cannot
stop promptly, shorten the distance between cancellation checks or make the current
I/O cancellable.