Skip to main content

Recurring (cron) jobs

A recurring job runs on a schedule with no payload. Include Zeridion::Flare::RecurringJob, give it a cron expression, and implement the single-argument #perform(ctx):

require "zeridion_flare/worker"

class NightlyCleanup
include Zeridion::Flare::RecurringJob
flare_options cron: "0 3 * * *", queue: "maintenance", timezone: "UTC"

def perform(ctx)
PurgeExpired.run
end
end

Note the signature — recurring jobs receive only ctx, no payload.

How it runs​

The worker announces each recurring schedule when it starts: the job type, the cron expression, the queue, and the timezone. The server owns the clock — on each tick it enqueues an execution, which the worker then picks up and runs through #perform(ctx) like any other job.

flare_options for recurring jobs​

OptionDefaultMeaning
cron:— (required)The cron expression, e.g. "0 3 * * *" for 03:00 daily.
timezone:"UTC"IANA timezone the cron is evaluated in.
job_type:the class's fully-qualified nameRouting key.
queue:"default"Queue the executions are served on.
max_attempts:3Attempt ceiling.
timeout:1800Per-execution timeout, in seconds.

Always set the timezone for non-UTC schedules​

timezone: defaults to "UTC". If your cron is meant to fire at a local wall time — say 03:00 in New York — set it explicitly:

flare_options cron: "0 3 * * *", queue: "maintenance", timezone: "America/New_York"

Without the right timezone the schedule fires at the wrong local time. The timezone travels with the schedule when the worker announces it.

Idempotency still applies​

Recurring executions are delivered at-least-once like every job. If a tick must run exactly once, dedupe on ctx.job_id.

See also​