Skip to main content

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​

MonthlyReport.java
@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.

Run and inspect it​

  1. Restart the worker and open Processes.
  2. Start monthly-report.
  3. Open Executions and watch the captured progress lines.
  4. Let the run finish. Its current state returns to idle without a stop command.
  5. 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.