2. An endless process
An endless process runs until an operator asks it to stop. It must check the library's cancellation signal and return promptly.
Register ticker
- Spring Boot
- Node.js
- Raw API
@SynapsysProcess(name = "ticker")
public class Ticker extends AbstractEndlessProcess {
@Override
protected void runForever(StopSignal stopSignal) throws Exception {
while (!stopSignal.isStopRequested()) {
System.out.println("tick");
Thread.sleep(2_000);
}
System.out.println("stopped cleanly");
}
}
Keep blocking intervals short enough for the stop requirement of your system.
Register before synapsys.start():
synapsys.endless('ticker', async (stop) => {
while (!stop.requested) {
console.log('tick');
await stop.sleep('2s');
}
console.log('stopped cleanly');
});
stop.sleep() wakes immediately on stop and is preferable to a bare timer.
Include the process in every heartbeat:
{
"workerName": "hello-worker",
"framework": "unknown",
"heartbeatInterval": 5,
"processes": [
{
"name": "ticker",
"type": "endless",
"currentState": "idle",
"ackToken": 0,
"runId": null
}
]
}
Your client must compare command tokens and own the execution lifecycle. Use the Raw API checklist.
Start and inspect it
Restart the worker, open Processes, and choose Start for ticker. Within one
heartbeat it reports running. Open Executions and its logs; new tick lines
arrive through later heartbeats.
Stop it
Choose Stop. The process first reports stopping, then idle after its body
returns. If it remains in stopping, the body is blocked or is not observing the
stop signal.
Commands carry increasing tokens. Repeated heartbeat responses cannot start a second copy because the worker applies only a token newer than the one it has acknowledged.