Skip to content

Schedule

Build a schedule object for batch/workflow jobs using friendly fields.

Examples:

schedule = Schedule(at_hours=[0])
schedule = Schedule(at_minutes=[0, 30], weekdays=["Mon", "Wed", "Fri"])
schedule = Schedule(at_minutes=[0], at_hours=[2], weekdays=["Sun"])
schedule = Schedule(cron_expression="0 0 7 * * 1-5", timezone="Europe/London")

You can either provide a raw cron_expression or use the human-readable helper parameters. The first time the cron string is needed, dt job cron compiles the helpers into cron syntax. Without a minute helper, the schedule runs at minute 0. Without minute and hour helpers, it runs at 00:00. A cron_expression without helpers is used as is, and dt is not called.

Parameters:

  • cron_expression

    (str, default: '' ) –

    A raw cron string with six fields: second, minute, hour, day of month, month and day of week (e.g. "0 0 */2 * * *" for every second hour). If the string has five fields, the schedule adds second 0 in front. Day of week is 0 (Sunday) to 6 (Saturday). If provided alongside helper parameters, the helpers take precedence.

  • at_minutes

    (list[int] | None, default: None ) –

    Specific minutes past the hour to run (e.g. [0, 30] for ":00" and ":30").

  • every_minute

    (int | None, default: None ) –

    Run every N minutes (e.g. 5 for every 5 minutes).

  • at_hours

    (list[int] | None, default: None ) –

    Specific hours of the day to run (0 -- 23).

  • every_hour

    (int | None, default: None ) –

    Run every N hours.

  • weekdays

    (list[str] | None, default: None ) –

    Days of the week to run (e.g. ["Mon", "Wed", "Fri"]). In the cron string, Sunday is day 0.

  • day_of_month

    (int | None, default: None ) –

    Day of the month to run (1 -- 31).

  • in_month

    (list[str] | None, default: None ) –

    Months to run in (e.g. ["Jan", "Apr", "Jul", "Oct"]).

  • every_month

    (int | None, default: None ) –

    Run every N months.

  • timezone

    (str | None, default: None ) –

    IANA time zone name (e.g. "America/New_York"). The job stores it and computes the run date (the rundate task argument) in this time zone. The scheduler computes the run times in UTC.

Example
>>> from datatailr import Schedule
>>> # At 02:00 every Sunday
>>> print(Schedule(at_minutes=[0], at_hours=[2], weekdays=["Sun"]))
0 0 2 * * 0
>>> # At 09:00 every Saturday and Sunday
>>> print(Schedule(at_minutes=[0], at_hours=[9], weekdays=["Sat", "Sun"]))
0 0 9 * * 0,6
>>> # A raw cron expression is used as is
>>> print(Schedule(cron_expression="0 0 7 * * 1-5", timezone="Europe/London"))
0 0 7 * * 1-5

get_cron_string

Return the compiled cron string.

Returns:

  • str –

    Cron string (str).

Examples:

>>> Schedule(
...     at_minutes=[0, 15, 30, 45],
...     at_hours=[0, 12],
...     weekdays=["Mon", "Wed", "Fri"],
...     day_of_month=15,
...     in_month=["Jan", "Jul"],
... ).get_cron_string()
'0 0,15,30,45 0,12 15 1,7 1,3,5'