Skip to content

Run work on a schedule

A scheduled job is work the platform starts on a timetable. At each due time it records an instance and sends a signed POST (a firing) to your application, which does the work and, if the job asks for it, reports when it finished. This page sets one up end to end.

Declare scheduled jobs with the rest of your definitions. The application’s service account has scheduled-job:sync for its own application.

set := sync.ForApplication("orders").
AddScheduledJob(sync.MakeScheduledJob("orders:nightly-reconcile", "Nightly reconcile", "0 0 2 * * *").
WithTimezone("Europe/London").
WithTargetURL("https://orders.example.com/webhooks/scheduled-job").
TracksCompletionEnabled().
WithTimeout(30))

Cron has six fields, seconds first: second minute hour day-of-month month day-of-week, so 0 0 2 * * * is 02:00:00 every day. A five-field expression is refused (CRON_INVALID_SHAPE). Jobs saved by older releases with five fields were converted (a 0 seconds field added) and, having never fired, set to PAUSED; resume the ones you want. See the cron reference.

Choose the settings with the receiver in mind:

Setting Use
tracksCompletion true when you want each run’s outcome recorded. The instance stays open until the receiver reports.
concurrent false (the default) means “never two runs at once”. The receiver enforces it, with a lock; the platform fires every slot regardless.
timeoutSeconds How long the platform waits for the HTTP answer (default 10, at most 300) and the budget passed to the receiver. Answer fast and work in the background.
deliveryMaxAttempts How many times a firing is sent before it counts as undeliverable (default 3).
payload Fixed JSON passed with every firing.
client Omit for a platform-wide job. A job that belongs to one tenant names its client.

Each firing is a JSON POST with jobId, jobCode, instanceId, scheduledFor (absent for a manual firing), firedAt, triggerKind (CRON or MANUAL), payload, tracksCompletion, concurrent and timeoutSeconds. It is signed like any delivery, always by the owning application’s service account, so verify it with that account’s signing secret (FLOWCATALYST_SIGNING_SECRET; see receive webhooks).

The SDK runners do the rest: look up the handler by jobCode, take the overlap lock, answer 202 at once, run the handler in the background, and report completion (the handler’s return value as the result, a thrown error as a failure).

verifier := webhook.NewVerifier(os.Getenv("FLOWCATALYST_SIGNING_SECRET"))
runner := scheduledjobs.NewBuilder(fcClient, postgreslock.New(pool)).
LockTTL(15 * time.Minute).
Handler("orders:nightly-reconcile", func(ctx context.Context, h *scheduledjobs.HandlerContext) (json.RawMessage, error) {
h.Log(ctx, "starting reconcile", nil)
// ... the work; honour ctx, which carries the job's timeout ...
return json.RawMessage(`{"reconciled":42}`), nil
}).
Build()
http.HandleFunc("POST /webhooks/scheduled-job", func(w http.ResponseWriter, r *http.Request) {
raw, _ := io.ReadAll(r.Body)
if err := verifier.Verify(raw, r.Header.Get(webhook.SignatureHeader), r.Header.Get(webhook.TimestampHeader)); err != nil {
http.Error(w, "invalid signature", http.StatusUnauthorized)
return
}
switch res := runner.Process(raw); res.Kind {
case scheduledjobs.ResultAccepted:
w.WriteHeader(http.StatusAccepted)
case scheduledjobs.ResultNotFound:
http.Error(w, res.Message, http.StatusNotFound)
default:
http.Error(w, res.Message, http.StatusBadRequest)
}
})

fcClient is a platform client with the service account’s credentials (it reports logs and completion). Use lock.NewMemory() only for a single process; postgreslock or redislock across replicas.

You answer The instance
2xx (the runners send 202) DELIVERED; with tracksCompletion, COMPLETED once you report
429 Re-queued for Retry-After (30 seconds when absent); no attempt spent
422 with FlowCatalyst-Outcome: reject DELIVERY_FAILED at once
Anything else, or nothing within the timeout Sent again, up to deliveryMaxAttempts, then DELIVERY_FAILED

Missed slots are not replayed: after an outage the job fires once, for the latest slot. If the work must cover a gap, use scheduledFor and your own record of the last successful run.

With tracksCompletion: true, an instance stays DELIVERED (shown as running) until the receiver calls POST /api/scheduled-jobs/instances/{instanceId}/complete with SUCCESS or FAILURE and an optional result. Progress lines go to POST /api/scheduled-jobs/instances/{instanceId}/log. The runners do both for you; the service account’s scheduled-job-instance:write permission allows it.

When a runner finds the lock for a non-concurrent job already held, it does not run the handler; for a job that tracks completion it reports a failure with the reason lock-held, so overlapping runs are visible rather than silent.

An application can fire its own jobs, for example to run the nightly reconcile right after an import. Look the job up by code, then fire it; the instance is MANUAL and goes through the same path, receiver included.

job, err := c.ScheduledJobs().GetByCode(ctx, "orders:nightly-reconcile", "" /* clientID */)
if err != nil { return err }
fired, err := c.ScheduledJobs().Fire(ctx, job.ID, &client.FireRequest{CorrelationID: importID})

A paused job can be fired by hand; an archived one cannot. Administrators can also fire any job from the console’s Scheduled jobs page, which lists every instance with its attempts and logs.