# Clocks


# Clock

class

prefect.schedules.clocks.Clock

(start_date=None, end_date=None, parameter_defaults=None, labels=None)[source]

Base class for Clocks

Args:

  • start_date (datetime, optional): an optional start date for the clock
  • end_date (datetime, optional): an optional end date for the clock
  • parameter_defaults (dict, optional): an optional dictionary of default Parameter values; if provided, these values will be passed as the Parameter values for all Flow Runs which are run on this clock's events
  • labels (List[str], optional): a list of labels to apply to all flow runs generated from this Clock

methods:                                                                                                                                                       

prefect.schedules.clocks.Clock.events

(after=None)[source]

Generator that emits clock events

Args:

  • after (datetime, optional): the first result will be after this date
Returns:
  • Iterable[datetime]: the next scheduled events



# IntervalClock

class

prefect.schedules.clocks.IntervalClock

(interval, start_date=None, end_date=None, parameter_defaults=None, labels=None)[source]

A clock formed by adding timedelta increments to a start_date.

IntervalClocks support any interval, but if deployed to Prefect Cloud only intervals of one minute or greater are allowed.

NOTE: If the IntervalClock start time is provided with a DST-observing timezone, then the clock will adjust itself appropriately. Intervals greater than 24 hours will follow DST conventions, while intervals of less than 24 hours will follow UTC intervals. For example, an hourly clock will fire every UTC hour, even across DST boundaries. When clocks are set back, this will result in two runs that appear to both be scheduled for 1am local time, even though they are an hour apart in UTC time. For longer intervals, like a daily clock, the interval clock will adjust for DST boundaries so that the clock-hour remains constant. This means that a daily clock that always fires at 9am will observe DST and continue to fire at 9am in the local time zone.

Note that this behavior is different from the CronClock.

Args:

  • interval (timedelta): interval on which this clock occurs
  • start_date (datetime, optional): first date of clock. If None, will be set to "2019-01-01 00:00:00 UTC"
  • end_date (datetime, optional): an optional end date for the clock
  • parameter_defaults (dict, optional): an optional dictionary of default Parameter values; if provided, these values will be passed as the Parameter values for all Flow Runs which are run on this clock's events
  • labels (List[str], optional): a list of labels to apply to all flow runs generated from this Clock
Raises:
  • TypeError: if start_date is not a datetime
  • ValueError: if provided interval is less than or equal to zero

methods:                                                                                                                                                       

prefect.schedules.clocks.IntervalClock.events

(after=None)[source]

Generator that emits clock events

Args:

  • after (datetime, optional): the first result will be after this date
Returns:
  • Iterable[ClockEvent]: the next scheduled events



# CronClock

class

prefect.schedules.clocks.CronClock

(cron, start_date=None, end_date=None, parameter_defaults=None, labels=None, day_or=None)[source]

Cron clock.

NOTE: If the CronClock's start time is provided with a DST-observing timezone, then the clock will adjust itself. Cron's rules for DST are based on clock times, not intervals. This means that an hourly cron clock will fire on every new clock hour, not every elapsed hour; for example, when clocks are set back this will result in a two-hour pause as the clock will fire the first time 1am is reached and the first time 2am is reached, 120 minutes later. Longer clocks, such as one that fires at 9am every morning, will automatically adjust for DST.

Note that this behavior is different from the IntervalClock.

NOTE: CronClock respects microseconds meaning for a clock that runs once a day, if the start time is (2020, 1, 1, 0, 0, 0, 1) then the first scheduled run will be (2020, 1, 2, 0, 0, 0, 0).

Args:

  • cron (str): a valid cron string
  • start_date (datetime, optional): an optional start date for the clock
  • end_date (datetime, optional): an optional end date for the clock
  • parameter_defaults (dict, optional): an optional dictionary of default Parameter values; if provided, these values will be passed as the Parameter values for all Flow Runs which are run on this clock's events
  • labels (List[str], optional): a list of labels to apply to all flow runs generated from this Clock
  • day_or (bool, optional): Control how croniter handles day and day_of_week entries. Defaults to True, matching cron which connects those values using OR. If the switch is set to False, the values are connected using AND. This behaves like fcron and enables you to e.g. define a job that executes each 2nd friday of a month by setting the days of month and the weekday.
Raises:
  • ValueError: if the cron string is invalid

methods:                                                                                                                                                       

prefect.schedules.clocks.CronClock.events

(after=None)[source]

Generator that emits clock events

Args:

  • after (datetime, optional): the first result will be after this date
Returns:
  • Iterable[ClockEvent]: the next scheduled events



# DatesClock

class

prefect.schedules.clocks.DatesClock

(dates, parameter_defaults=None, labels=None)[source]

Clock that fires on specific dates

Args:

  • dates (List[datetime]): a list of datetimes on which the clock should fire
  • parameter_defaults (dict, optional): an optional dictionary of default Parameter values; if provided, these values will be passed as the Parameter values for all Flow Runs which are run on this clock's events
  • labels (List[str], optional): a list of labels to apply to all flow runs generated from this Clock

methods:                                                                                                                                                       

prefect.schedules.clocks.DatesClock.events

(after=None)[source]

Generator that emits clock events

Args:

  • after (datetime, optional): the first result will be after this date
Returns:
  • Iterable[ClockEvent]: the next scheduled events



# RRuleClock

class

prefect.schedules.clocks.RRuleClock

(rrule_obj, start_date=None, end_date=None, parameter_defaults=None, labels=None)[source]

Clock that supports iCal style RRule (recurrence rules).

See below links for helpful info:

IETF iCalendar specification RFC5545: https://icalendar.org/iCalendar-RFC-5545/3-8-5-3-recurrence-rule.html

dateutil rrule module, an implementation of the iCal specification recurrence rules: https://dateutil.readthedocs.io/en/stable/rrule.html

Args:

  • rrule_obj (rrulebase): an rrule or rruleset object
  • start_date (datetime, optional): an optional start date for the clock
  • end_date (datetime, optional): an optional end date for the clock
  • parameter_defaults (dict, optional): an optional dictionary of default Parameter values; if provided, these values will be passed as the Parameter values for all Flow Runs which are run on this clock's events
  • labels (List[str], optional): a list of labels to apply to all flow runs generated from this Clock
Raises:
  • TypeError: if the rrule_obj passed in is not an rrule object

methods:                                                                                                                                                       

prefect.schedules.clocks.RRuleClock.events

(after=None)[source]

Generator that emits clock events

Args:

  • after (datetime, optional): the first result will be after this date
Returns:
  • Iterable[datetime]: the next scheduled events



This documentation was auto-generated from commit bd9182e
on July 31, 2024 at 18:02 UTC