Skip to content

Scheduled-job scheduler

The scheduled-job scheduler fires scheduled jobs: it evaluates each active job’s cron expressions, records one instance per firing, and delivers a signed POST to the job’s target. It is the internal/platform/scheduledjob/scheduler package, switched on with FC_SCHEDULED_JOB_ENABLED (alias SCHEDULED_JOB_SCHEDULER_ENABLED, default off).

It is a different component from the dispatch scheduler (internal/platform/scheduler), which publishes dispatch jobs to queues. Scheduled-job firings do not go through queues or the router: the scheduler delivers them itself. The concept page explains why firings are not dispatch jobs.

flowchart LR
  J[("msg_scheduled_jobs<br/>ACTIVE")] --> P["Poller<br/>latest due slot per job"]
  P -->|"one transaction"| T[("msg_scheduled_job_ticks<br/>(job, slot) primary key")]
  P -->|"same transaction"| I[("msg_scheduled_job_instances<br/>QUEUED")]
  P -.->|wake| D["Dispatcher"]
  I --> D
  D -->|"signed POST"| E["Target endpoint"]
  D -->|"DELIVERED, retry, DEFERRED, DELIVERY_FAILED"| I
  E -.->|"complete, logs (tracksCompletion)"| API["Instance API"]
  API --> I

Each pass the poller reads every ACTIVE job and, for each one:

  1. Computes the latest cron slot in the window (last_fired_at, now] (or from the job’s created_at if it has never fired), across all of the job’s expressions, in the job’s time zone. Only the latest slot fires: if the platform was down for an hour, a job that runs every minute fires once on recovery, not sixty times (skip-missed).
  2. Claims the tick: inserts (scheduled_job_id, scheduled_for) into msg_scheduled_job_ticks with ON CONFLICT DO NOTHING, and the QUEUED instance row, in one transaction. If the tick row already exists, nothing is inserted and the slot is logged as already claimed.
  3. Advances last_fired_at to the slot, monotonically, whether or not this pass inserted it.

Then it sleeps until the earliest upcoming slot across all jobs (plus 20 ms, so it lands just after the slot), never less than 200 ms and never more than FC_SCHEDULED_JOB_POLL_SECONDS (30). The poll interval is therefore how quickly a new or edited job is noticed, not the firing precision: a job every 5 seconds fires every 5 seconds. A pass that queues an instance wakes the dispatcher at once.

The job’s concurrent flag is not checked here. Whether a new run may overlap a running one is the receiver’s decision; the flag is passed to it in the envelope.

Exactly once per tick. The tick table’s primary key is the guarantee, not the leader gate. Two pollers running at once (a failover overlap, a split brain) both try to insert the same tick and only one succeeds. It is a separate table because the instance table is partitioned by created_at, and PostgreSQL requires the partition key in every unique index. Tick rows are pruned after 30 days.

Every FC_SCHEDULED_JOB_DISPATCH_SECONDS (5), or at once when woken, the dispatcher:

  1. Abandons stuck instances. An instance IN_FLIGHT for longer than the longest possible call (FC_SCHEDULED_JOB_HTTP_TIMEOUT_MAX_SECONDS, 300) plus 60 seconds belonged to a process that died mid-delivery. It is marked DELIVERY_FAILED with an ABANDONED reason and a log line, and is never re-fired: whether the receiver got the call is unknown, and the platform promises at most one firing per tick.
  2. Claims up to FC_SCHEDULED_JOB_DISPATCH_BATCH (32) QUEUED instances whose not_before has passed, marks each IN_FLIGHT (counting the attempt), and posts the firing.

The request:

Part Value
Body jobId, jobCode, instanceId, scheduledFor, firedAt, triggerKind (CRON, MANUAL), correlationId, payload, tracksCompletion, timeoutSeconds, concurrent (camelCase: the SDK runners decode these exact keys)
Authorization Bearer <token> of the owning application’s service account, when it has one
X-FlowCatalyst-Signature, X-FlowCatalyst-Timestamp HMAC-SHA256 over the timestamp followed by the body, with the service account’s signing secret, the same scheme as dispatch-job deliveries
Timeout The job’s timeoutSeconds, capped at 300 s; 10 s when it sets none

Credentials are resolved per application through a cache that lives one minute, so a rotated secret takes effect without a restart. A job with no application link, or an application whose service account has no webhook credentials, is delivered unsigned with a warning in the log; an SDK receiver then rejects it with a descriptive 401, which lands in the instance’s delivery error.

Outbound calls go through the outbound delivery guard: a job’s target URL is customer input, so loopback, link-local, metadata and private destinations are refused unless allowed.

Answer Instance becomes Attempt counted
Any 2xx DELIVERED (or stays COMPLETED if the receiver already reported completion) Yes
429 QUEUED again with not_before = now + Retry-After (seconds or an HTTP date; 30 s when absent, at most an hour) No (the attempt is given back)
422 with FlowCatalyst-Outcome: reject DELIVERY_FAILED at once Yes
Anything else, or a network error QUEUED for the next dispatch pass, or DELIVERY_FAILED once the job’s deliveryMaxAttempts (default 3) is reached Yes
The job was deleted while the instance waited DELIVERY_FAILED (“no longer exists”) No

There is no backoff between ordinary retries beyond the dispatch interval: a failing target is tried again about 5 seconds later, up to the attempt limit. A job that tracks completion (tracksCompletion) stays DELIVERED until the receiver reports COMPLETED or FAILED through POST /api/scheduled-jobs/instances/{instanceId}/complete, and it may append log lines meanwhile.

stateDiagram-v2
  [*] --> QUEUED: tick claimed, or fired by hand
  QUEUED --> IN_FLIGHT: dispatcher
  IN_FLIGHT --> DELIVERED: 2xx
  IN_FLIGHT --> QUEUED: failure with attempts left, or 429
  IN_FLIGHT --> DELIVERY_FAILED: attempts used up, reject, or abandoned
  DELIVERED --> COMPLETED: receiver reports success
  DELIVERED --> FAILED: receiver reports failure

POST /api/scheduled-jobs/{id}/fire creates a MANUAL instance outside the cron schedule (no tick is claimed). An application’s own service account may fire its own applications’ jobs: the built-in application-service role carries platform:application-service:scheduled-job:fire, and the endpoints confine such a caller to jobs of the applications it is bound to. Pause, resume and archive are /pause, /resume and /archive on the same resource.

Expressions are six fields, seconds first (sec min hour day-of-month month day-of-week), parsed with robfig/cron and evaluated in the job’s IANA time zone. ValidateCron refuses anything else at create, update, sync and function publish, so a stored expression always fires. Earlier releases accepted five-field expressions that never fired: migration 111 prefixed a 0 seconds field to each and paused every active job it changed, so nothing starts firing unexpectedly; resume the ones you want. Seven-field expressions (with a year) have no equivalent and are left as they are; the poller logs a warning once per process for any expression it cannot parse. See the cron reference.

Both loops run only on the leader of the election on <FC_STANDBY_LOCK_KEY>:scheduled-job. Without standby every copy considers itself the leader, so run one. The loops claim without row locks, a single-active design; the leader gate keeps work in one place, and the tick table keeps the once-per-tick promise even if two copies overlap during a failover.

On failover the new leader’s first poller pass fires each job’s latest missed slot (if it has not been claimed), and its dispatcher picks up the QUEUED instances. Instances the old leader left IN_FLIGHT are abandoned after the grace period rather than sent twice.

Instances and their logs live in monthly partitions (msg_scheduled_job_instances, msg_scheduled_job_instance_logs) dropped by the stream processor’s partition manager after FC_STREAM_PARTITION_RETENTION_DAYS_SCHEDULED_JOBS (30 days). That only happens where the stream processor runs; tick rows are pruned by the poller itself after 30 days.

Variable Default Effect
FC_SCHEDULED_JOB_ENABLED false Run the scheduler
FC_SCHEDULED_JOB_POLL_SECONDS 30 Longest the poller sleeps; how fast new and edited jobs are noticed
FC_SCHEDULED_JOB_DISPATCH_SECONDS 5 Dispatch interval, and so the gap between retries
FC_SCHEDULED_JOB_DISPATCH_BATCH 32 Instances per dispatch pass
FC_SCHEDULED_JOB_HTTP_TIMEOUT_SECONDS 10 Call timeout when a job sets no timeoutSeconds
FC_SCHEDULED_JOB_HTTP_TIMEOUT_MAX_SECONDS 300 Ceiling on a job’s timeoutSeconds; also sets the abandon grace

See the environment reference.

Situation What happens
The platform is down across several slots On recovery each job fires once, for its latest missed slot
Two schedulers run at once Each slot is claimed once in the database; the second sees the claim and does not fire
The process dies mid-delivery The instance is abandoned after the grace period and not re-fired
The target is down Retried every dispatch pass until deliveryMaxAttempts, then DELIVERY_FAILED
The target answers 429 Deferred by Retry-After without spending an attempt
The receiver’s runs take longer than the interval A new firing is sent anyway; the receiver applies its own overlap lock when concurrent is false
A job has no application link or credentials Delivered unsigned with a warning; a verifying receiver refuses it and the error is recorded