| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Arbiter.Worker.Cron
Description
Cron schedule declarations and worker integration.
Synopsis
- cronJob :: Text -> Text -> OverlapPolicy -> (TickKind -> UTCTime -> JobWrite payload) -> Either String (CronJob payload)
- cronJobInTimezone :: Text -> Text -> Text -> OverlapPolicy -> (TickKind -> UTCTime -> JobWrite payload) -> Either String (CronJob payload)
- enumMinutes :: UTCTime -> UTCTime -> [UTCTime]
- formatMinute :: UTCTime -> Text
- formatMinuteInTimezone :: Maybe Text -> UTCTime -> Text
- matchesInTimezone :: Maybe Text -> CronSchedule -> UTCTime -> Bool
- nextRunFromExpression :: Maybe Text -> Text -> UTCTime -> Maybe UTCTime
- nextRunInTimezone :: Maybe Text -> CronSchedule -> UTCTime -> Maybe UTCTime
- overlapPolicyFromText :: Text -> Maybe OverlapPolicy
- overlapPolicyToText :: OverlapPolicy -> Text
- resolveTZ :: Text -> Maybe TZ
- truncateToMinute :: UTCTime -> UTCTime
- updateCronScheduleChecked :: MonadArbiter m => Text -> CronScheduleUpdate -> m (Either Text Int64)
- validateCronScheduleUpdate :: CronScheduleUpdate -> Either Text ()
- data BackfillPolicy
- data CronJob payload = CronJob {
- name :: Text
- cronExpression :: Text
- overlap :: OverlapPolicy
- backfill :: BackfillPolicy
- timezone :: Maybe Text
- builder :: TickKind -> UTCTime -> JobWrite payload
- data OverlapPolicy
- data TickKind
- computeDelayMicros :: UTCTime -> Int
- enumerateCatchUpTicks :: BackfillPolicy -> Maybe UTCTime -> UTCTime -> [UTCTime]
- initCronSchedules :: MonadArbiter m => SchemaName -> Text -> [CronJob payload] -> LogConfig -> m ()
- makeDedupKey :: CronJob payload -> UTCTime -> Text
- newCronLog :: MonadIO m => LogConfig -> m CronLog
- processCronCatchUp :: QueueOperation m payload => CronLog -> Text -> Text -> [CronJob payload] -> UTCTime -> m ()
- processRunRequests :: forall payload m. QueueOperation m payload => CronLog -> Text -> [CronJob payload] -> UTCTime -> m ()
- runCronScheduler :: QueueOperation m payload => TVar WorkerState -> TVar Bool -> LogConfig -> SchemaName -> Text -> [CronJob payload] -> m ()
- data CronLog
Documentation
Source #cronJob :: Text -> Text -> OverlapPolicy -> (TickKind -> UTCTime -> JobWrite payload) -> Either String (CronJob payload)
Arguments
| :: Text | Schedule name (used in dedup keys and logging) |
| -> Text | Cron expression (5-field: minute hour day-of-month month day-of-week) |
| -> OverlapPolicy | |
| -> (TickKind -> UTCTime -> JobWrite payload) | Job builder. Receives the tick kind and the tick time. |
| -> Either String (CronJob payload) |
Build a CronJob. A bad expression returns Left. The expression is
evaluated in UTC. cronJobInTimezone is the local-time form. Set backfill
by record update.
cronJob "nightly-report" "0 3 * * *" SkipOverlap (\_kind _tick -> defaultJob (GenerateReport "nightly"))
Source #cronJobInTimezone :: Text -> Text -> Text -> OverlapPolicy -> (TickKind -> UTCTime -> JobWrite payload) -> Either String (CronJob payload)
Arguments
| :: Text | Schedule name |
| -> Text | IANA tz name (e.g. |
| -> Text | Cron expression (5-field) |
| -> OverlapPolicy | |
| -> (TickKind -> UTCTime -> JobWrite payload) | |
| -> Either String (CronJob payload) |
Like cronJob but evaluated in a specific timezone. The tz name is
validated eagerly against the bundled tzdata database.
Source #enumMinutes :: UTCTime -> UTCTime -> [UTCTime]
Enumerate all minute-boundary times from start through end (inclusive).
Both start and end should be truncated to minute boundaries.
Source #formatMinuteInTimezone :: Maybe Text -> UTCTime -> Text
Format a UTC tick as YYYY-MM-DDTHH:MM in the given timezone.
DST fall-back maps two UTC instants to the same local minute. Dedup keys
built from it collapse those to a single fire.
Source #matchesInTimezone :: Maybe Text -> CronSchedule -> UTCTime -> Bool
Source #nextRunFromExpression :: Maybe Text -> Text -> UTCTime -> Maybe UTCTime
'nextRunInTimezone' over an unparsed expression. A bad one returns 'Nothing'.
Source #nextRunInTimezone :: Maybe Text -> CronSchedule -> UTCTime -> Maybe UTCTime
Source #overlapPolicyFromText :: Text -> Maybe OverlapPolicy
Parse an OverlapPolicy from text.
Source #overlapPolicyToText :: OverlapPolicy -> Text
Convert an OverlapPolicy to its text representation.
Source #truncateToMinute :: UTCTime -> UTCTime
Truncate a UTCTime to the current minute (zero out seconds).
Source #updateCronScheduleChecked :: MonadArbiter m => Text -> CronScheduleUpdate -> m (Either Text Int64)
updateCronScheduleUnchecked behind
validateCronScheduleUpdate. Returns rows affected (0 = not found).
Source #validateCronScheduleUpdate :: CronScheduleUpdate -> Either Text ()
Check a cron patch before it is written. At tick time a bad override stops firing or falls back to the default.
Source #data BackfillPolicy
Bound on replay of missed ticks. Applies at startup and mid-flight.
Constructors
| NoBackfill | Drop missed minutes silently. Default. |
| Backfill NominalDiffTime | Replay missed minutes up to the given duration. |
Instances
A cron schedule. Built with cronJob, or cronJobInTimezone for a non-UTC one.
Constructors
| CronJob | |
Fields
| |
Instances
| Generic (CronJob payload) Source # | |||||
Defined in Arbiter.Worker.Cron.Types Associated Types
| |||||
| type Rep (CronJob payload) Source # | |||||
Defined in Arbiter.Worker.Cron.Types type Rep (CronJob payload) = D1 ('MetaData "CronJob" "Arbiter.Worker.Cron.Types" "arbiter-worker-0.1.0.0-inplace" 'False) (C1 ('MetaCons "CronJob" 'PrefixI 'True) ((S1 ('MetaSel ('Just "name") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "cronExpression") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "overlap") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 OverlapPolicy))) :*: (S1 ('MetaSel ('Just "backfill") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BackfillPolicy) :*: (S1 ('MetaSel ('Just "timezone") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: S1 ('MetaSel ('Just "builder") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (TickKind -> UTCTime -> JobWrite payload)))))) | |||||
Source #data OverlapPolicy
How overlapping cron ticks are deduplicated.
Constructors
| SkipOverlap | At most one pending or running job per schedule. |
| AllowOverlap | One job per tick. Concurrent execution of prior ticks is allowed. |
Instances
| Eq OverlapPolicy Source # | |||||
Defined in Arbiter.Worker.Cron.Types Methods #(==) :: OverlapPolicy -> OverlapPolicy -> Bool #(/=) :: OverlapPolicy -> OverlapPolicy -> Bool | |||||
| Generic OverlapPolicy Source # | |||||
Defined in Arbiter.Worker.Cron.Types Associated Types
| |||||
| Show OverlapPolicy Source # | |||||
Defined in Arbiter.Worker.Cron.Types Methods #showsPrec :: Int -> OverlapPolicy -> ShowS #show :: OverlapPolicy -> String #showList :: [OverlapPolicy] -> ShowS | |||||
| type Rep OverlapPolicy Source # | |||||
Whether a tick is for the current minute or a replay of a past minute.
Source #computeDelayMicros :: UTCTime -> Int
Delay in microseconds until the next minute boundary, clamped to
[0, .maxTickDelayMicros]
Source #enumerateCatchUpTicks :: BackfillPolicy -> Maybe UTCTime -> UTCTime -> [UTCTime]
Minutes to evaluate for a processCronCatchUp call. Returns [] when
the watermark is at or past currentTick.
Source #initCronSchedules :: MonadArbiter m => SchemaName -> Text -> [CronJob payload] -> LogConfig -> m ()
Upsert default expression and overlap for each CronJob into the
cron_schedules table. Preserves any user overrides and enabled state.
Source #makeDedupKey :: CronJob payload -> UTCTime -> Text
Dedup key for a cron job, from its code-defined overlap and timezone.
Source #newCronLog :: MonadIO m => LogConfig -> m CronLog
A CronLog with no gate tripped, for one scheduler run.
Source #processCronCatchUp :: QueueOperation m payload => CronLog -> Text -> Text -> [CronJob payload] -> UTCTime -> m ()
Arguments
| :: QueueOperation m payload | |
| => CronLog | |
| -> Text | |
| -> Text | Queue name |
| -> [CronJob payload] | |
| -> UTCTime | Current wall-clock time |
| -> m () |
Scheduler catch-up step. Each cron runs in its own transaction. Backfill schedules hold a per-(schema, queue, name) advisory lock.
Source #processRunRequests :: forall payload m. QueueOperation m payload => CronLog -> Text -> [CronJob payload] -> UTCTime -> m ()
Claim and fire every schedule with a pending run request. A SkipOverlap
schedule reuses its constant dedup key. A manual run is skipped while one of
its jobs is active.
The claim and the insert are atomic. If either fails the other rolls back.
Source #runCronScheduler :: QueueOperation m payload => TVar WorkerState -> TVar Bool -> LogConfig -> SchemaName -> Text -> [CronJob payload] -> m ()
Arguments
| :: QueueOperation m payload | |
| => TVar WorkerState | |
| -> TVar Bool | Set by the run-now listener when a schedule this pool owns is requested. |
| -> LogConfig | |
| -> SchemaName | |
| -> Text | Queue name (recorded on each schedule row). |
| -> [CronJob payload] | |
| -> m () |
Scheduler entry point. Exits when the worker state becomes ShuttingDown.