ClusterCron unstable
Runs recurring cron jobs through cluster sharding.
This module turns a Cron.Cron schedule into a Layer that coordinates one
recurring job across a cluster. It registers a singleton for the initial
scheduling step and a persisted entity message for each run. This is useful
for distributed maintenance work where the job should be owned by the cluster
rather than by every runner independently.
With calculateNextRunFromPrevious, every run is processed by a single
entity per cron job, so runs never overlap and are caught up in order. The
scheduled time of the current run is available through
CurrentScheduledTime.
Constructors
Creates a layer that runs a cron job through the cluster sharding system.
Details
The job is scheduled as persisted entity messages, with an initial singleton scheduling step and optional controls for shard group, next-run calculation, and skipping stale scheduled runs.
A run that fails or dies is logged and not retried, and the next run is
scheduled as usual. To retry typed failures, apply Effect.retry inside
execute with your own stopping policy.
Signature
declare function make<E, R>(options: { readonly calculateNextRunFromPrevious?: boolean; readonly cron: Cron; readonly execute: Effect<void, E, R>; readonly name: string; readonly shardGroup?: string; readonly skipIfOlderThan?: Input;}): Layer<never, never, Sharding | Exclude<Exclude<R, CurrentScheduledTime | CronSchedule>, Scope>>Services
CronSchedule
unstableService tag and entity annotation for the effective schedule of a cron job.
When to use
Use to read a job's effective schedule inside the execute effect of make,
or read it from entity.protocol.annotations with Context.getOption when
inspecting registered cron entities.
Signature
declare class CronSchedule extends Shape<"effect/cluster/ClusterCron/CronSchedule", { readonly calculateNextRunFromPrevious: boolean; readonly cron: Cron; readonly skipIfOlderThan: Duration;}, this> { constructor(_: never);}CurrentScheduledTime
unstableService tag for the scheduled time of the cron run currently executing.
When to use
Use to read the time the current run was scheduled for, inside the
execute effect of make.
Signature
declare class CurrentScheduledTime extends Shape<"effect/cluster/ClusterCron/CurrentScheduledTime", Utc, this> { constructor(_: never);}