Skip to main content

Schedule Receipts

Every scheduling call returns a receipt: what was scheduled, and where it was stored when the call returned. In particular, it tells you clearly whether the job is already on the cluster's master database, or not yet. Most apps never need it.

var receipt = await scheduler.OnceNowAsync<InvoiceHandler>(msg);

Console.WriteLine($"{receipt.JobId} on {receipt.ClusterId}: {receipt.Status}");
PropertyWhat it is
JobIdThe job's id
ClusterIdThe cluster the job went to (the resolved one, see Several Clusters)
StatusWhere the job was stored when the call returned (below)
ContextThe scheduled job, with its settings
AgentConnectionId, BucketId, AgentWorkerIdWhere it was handed to; empty when it's stored on master

Recurring schedules return a RecurringScheduleReceipt, the same with a RecurringScheduleId.

A receipt doesn't change afterwards: Status keeps its value from the moment of the call.

Where the Job Was Stored​

StatusMeaning
AcceptedOnTransportSaved on an agent connection and handed to a worker's bucket. A worker saves it on the cluster's master database shortly after.
StoredOnMasterSaved directly on the master database, for example when no worker was ready to take it, or the cluster is migrating.

AcceptedOnTransport is the normal, fast path: the call returns without waiting for the master database. Until a worker moves the job to master, a few moments later, it exists only on the agent connection. The receipt says so explicitly, so nothing assumes the job is already on master.

With stable agent connection servers, the risk is close to zero: the job is only lost if the agent connection's server crashes and loses its data in those few moments, before the job reaches master.

Confirming on Master​

For the rare job where even that risk isn't acceptable, confirm it on master:

var receipt = await scheduler.OnceNowAsync<InvoiceHandler>(msg);
await receipt.ConfirmOnMasterAsync();
// the job is now saved on the master database
  • When it returns, the job is on master. For a StoredOnMaster receipt it returns right away.
  • To confirm many jobs, pass all the receipts at once: scheduler.Advanced.ConfirmOnMasterAsync(receipts). It's one batch instead of one call per job.
  • Recurring schedule receipts have the same ConfirmOnMasterAsync().

Things to know:

  • Use it only where you need it. With stable agent connections, jobs reach master without it; confirming every job just slows them down.
  • A confirmed job can start a little later, because it's picked up from master instead of going straight to its worker.
  • Calling it again is safe, and never creates a second copy. If it throws, the job may or may not be saved: call it again.
  • Don't confirm late. JobMaster runs jobs at least once: confirming after the cluster's data retention has deleted an already-finished job saves it again, and it runs again. Confirm right after scheduling, not hours later.