cron

Generated by tinox doc

tinox.core.cron, bundled with the compiler and also available as a standalone tinox-central package.

Parse and match

import tinox.core.cron
import tinox.core.time
class Main
{
    fnc main() -> Int32
    {
        // every day at 09:00
        const expr: CronExpr = Cron::parse("0 9 * * *")
        const now: Int64 = Time::now()
        println("matches now: " + Cron::matches(expr, now).toString())
        println("next run at: " + Cron::nextRun(expr).toString())
        return 0
    }
}

class Cron

* Five numeric fields: minute hour day-of-month month day-of-week. * Fields accept *, comma lists, inclusive ranges, and /positive-step * on * or a range (for example a wildcard step of 15, or 1-10/2). * Weekdays are 0-7, * Sunday is 0 or 7. Names, macros, seconds, L, W and # are rejected. * A bare * day field is unrestricted; otherwise day-of-month and * day-of-week use traditional cron OR semantics when both are restricted. * All timestamps are Unix milliseconds in UTC, 1970 through 9999; * matches() ignores seconds/milliseconds within the scheduled minute.

Methods

@Throwsfn parse(expr: String) → CronExpr
@Throwsfn number(text: String) → Int64
@Throwsfn values(field: String, minimum: Int64, maximum: Int64) → List<Int64>
@Throwsfn validateTimestamp(timestamp: Int64) → Nothing
fn leap(year: Int64) → Bool
fn monthDays(year: Int64, month: Int64) → Int64
fn date(days: Int64) → List<Int64>
fn dayMatches(expr: CronExpr, dom: List<Int64>, dow: List<Int64>, day: Int64, weekday: Int64) → Bool
@Throwsfn matches(expr: CronExpr, timestamp: Int64) → Bool
@Throwsfn nextRun(expr: CronExpr) → Int64
Return the first matching minute boundary strictly after now.
@Throwsfn nextRunAfter(expr: CronExpr, timestamp: Int64) → Int64
* Deterministic nextRun variant. Search at most one Gregorian * 400-year cycle; impossible dates and exhausted years throw.
@Throwsfn nextMinute(current: Int64, field: String) → Int64
@Throwsfn getCurrentMinute(sec: Int64) → Int64

@Errorclass CronError

* Invalid cron expression or timestamp.

Fields

messageString

class CronExpr

Validated by Cron::parse, or at evaluation when constructed directly.

Fields

minuteString
hourString
dayOfMonthString
monthString
dayOfWeekString

class CronJob

Fields

exprCronExpr
callbackfnc() -> Nothing
lastRunInt64 Last attempted scheduled UTC minute boundary; -1 means never run.

class CronScheduler

Fields

jobsList<CronJob>
runningBool

Methods

fn new() → CronScheduler
fn addJob(scheduler: CronScheduler, expr: String, callback: fnc() -> Nothing) → Nothing
fn start(scheduler: CronScheduler) → Nothing
fn stop(scheduler: CronScheduler) → Nothing
@Throwsfn tick(scheduler: CronScheduler) → Nothing
@Throwsfn tickAt(scheduler: CronScheduler, now: Int64) → Nothing
Caller-driven, single-threaded tick; missed minutes are not replayed. * Repeated or backward ticks never re-run an already executed minute.

class ScheduledJob

* State of one @Scheduled job (used by the generated runner; usable directly). * Times are Unix milliseconds in UTC -- the schedule is always evaluated in UTC, so there * are no daylight-saving gaps or repeats. A job runs on one thread: an occurrence never * overlaps itself, and minutes that pass while a run is still executing are skipped, not * replayed (misfire policy "skip"). The state is in memory only; a restart forgets * `lastMinute`; the first run after a restart is the next matching minute boundary, so a restart inside * a matching minute skips it and one right before a boundary may repeat nothing.

Fields

exprCronExpr
lastMinuteInt64 Last claimed UTC minute boundary (ms)

Methods

fnc create(cron: String) → ScheduledJob
* Parses the expression; an invalid one is a hard error at startup. The minute in progress * is already claimed, so the first run is the next minute boundary (no late run at startup).
fnc createAt(cron: String, nowMs: Int64) → ScheduledJob
Like create, with an explicit "now" (tests): minutes up to and including nowMs's are not run
fn due(nowMs: Int64) → Int64
* The minute boundary to run if the job is due at nowMs, otherwise -1. Claims the minute, so * repeated calls within it (and backward clock steps) never return it twice.
fn nowMs() → Int64
fn pause(ms: Int64) → Nothing
Pause between checks (cancellation point)