Events and logging
The scheduler tells you what happens on this instance through events. For the view across all instances, use history.
In Node.js, on(), once() and off() work like Node’s EventEmitter, and are typed: the payload type follows from the event name. In .NET each event is a C# event (+=, -=) with an EventHandler<T>.
The events
Section titled “The events”| Node.js | .NET | When | Payload (.NET type) |
|---|---|---|---|
start |
Started |
This instance won a run and is about to call the handler | job, slot, attempt, reason (RunStartEvent) |
success |
Succeeded |
The handler returned | a run record (RunRecord) |
failure |
Failed |
The handler threw, or its timeout passed | run record + cause (RunFailureEvent) |
interrupted |
Interrupted |
A stop or a takeover cancelled the run, and the handler then threw | run record + cause, handed over (RunInterruptedEvent) |
skip |
Skipped |
A run was due and this instance didn’t run it | job, slot, reason (SkipEvent) |
lost |
Lost |
A backup took over a run this instance was executing, or its lease couldn’t be renewed in time | job, slot, attempt (LostEvent) |
error |
Error |
A backend or setup problem | error, and the job and slot if known (SchedulerErrorEvent) |
flowchart TD
due["a slot is due on this instance"] --> claim{"claim"}
claim -- "another instance has it" --> skipTaken["skip (taken)"]
claim -- "previous run still going" --> skipOverlap["skip (overlap)"]
claim -- "this instance was too late" --> skipLate["skip (late)"]
claim -- "the store failed" --> err["error"]
claim -- "won" --> start["start"]
start --> run{"how does the handler end?"}
run -- "returns" --> success["success"]
run -- "throws or times out" --> failure["failure"]
run -- "throws after a stop or a takeover" --> interrupted["interrupted"]
start -. "lease not renewed in time" .-> lost["lost"]
Skips are normal
Section titled “Skips are normal”With three instances, every run produces one start and two skip events with reason taken. That is the system working. The reasons:
| Node.js | .NET | Meaning |
|---|---|---|
'taken' |
SkipReason.Taken |
Another instance won this run |
'overlap' |
SkipReason.Overlap |
The previous run of this job is still going (the default overlap, skip) |
'late' |
SkipReason.Late |
This instance reached the run later than its lateness limit. lateMs (Late) says how late |
Failures and their cause
Section titled “Failures and their cause”run.error (run.Error) is the message as text, the same string that is stored in history. run.cause (run.Cause) is what the handler actually threw, so you can inspect it:
Interrupted is not a failure
Section titled “Interrupted is not a failure”A run that was stopped by a deploy, or taken over, didn’t fail. It is reported separately so your alerts stay quiet during deploys.
This instance was running a job and gave it up: a heartbeat found that a backup had taken the run over, or no heartbeat had been confirmed for a whole lease, so a backup may be taking it over. That happens when the instance couldn’t renew its lease: it was frozen, or cut off from the store. The run is cancelled at the same moment.
A lost event now and then after a long pause is expected. Frequent ones mean the lease is too short for your environment.
Errors
Section titled “Errors”Problems that are not a job failing: the store is unreachable, a claim couldn’t be sent, a result couldn’t be saved.
If nobody listens for errors, they are written to the logger. They never crash the process.
Metrics
Section titled “Metrics”Events map directly onto metrics:
Remember that these count what happened on one instance. Sum them across instances for the whole service.
Listeners can’t break a run
Section titled “Listeners can’t break a run”A listener that throws (in Node.js also an async listener whose promise rejects) is caught and logged. It doesn’t affect the run or the other listeners.
Built-in logging
Section titled “Built-in logging”log: true writes one line for each of the events above, without any code:
The scheduler logs each of the events above through ILogger, under the category Anarchon.Scheduler: runs at Debug, failed and lost runs at Warning, errors nobody handles at Error. Give it a LoggerFactory, or use a host, whose factory AddAnarchon() takes:
The log messages have event IDs (1 started, 2 finished, 3 failed, 4 interrupted, 5 skipped, 6 lost, 7 unhandled error), and their values are structured fields (Job, Due, Attempt…) for log stores that index them. The rest of this section is about Node.js.
Failures and lost runs go to logger.warn; the rest go to logger.info.
Your own logger (Node.js)
Section titled “Your own logger (Node.js)”Any object with warn and error methods works. info is optional.
With log: false (the default) the logger is still used for error events nobody listens for.
- History: the view across all instances
- Events reference: every payload field