Message period

FixedDurationPeriod

class daf.message.messageperiod.FixedDurationPeriod(duration: timedelta, next_send_time: timedelta | datetime | None = None)

A fixed message (sending) period.

Parameters:
  • duration (timedelta) – The period duration (how much time to wait after every send).

  • next_send_time (datetime | timedelta) – Represents the time at which the message should first be sent. Use datetime to specify the exact date and time at which the message should start being sent. Use timedelta to specify how soon (after creation of the object) the message should start being sent.

adjust(minimum: timedelta) None

Adjust the period to always be greater than the minimum.

calculate()

Calculates the next datetime the message is going to be sent.

defer(dt: datetime)

Defers advertising until dt This should be used for overriding the normal next datetime the message was supposed to be sent on.

get() datetime

Returns the next datetime the message is going to be sent.

RandomizedDurationPeriod

class daf.message.messageperiod.RandomizedDurationPeriod(minimum: timedelta, maximum: timedelta, next_send_time: timedelta | datetime | None = None)

A randomized message (sending) period. After every send, the message will wait a different randomly chosen period within minimum and maximum.

Parameters:
  • minimum (timedelta) – Bottom limit of the randomized period.

  • maximum (timedelta) – Upper limit of the randomized period.

  • next_send_time (datetime | timedelta) – Represents the time at which the message should first be sent. Use datetime to specify the exact date and time at which the message should start being sent. Use timedelta to specify how soon (after creation of the object) the message should start being sent.

adjust(minimum: timedelta) None

Adjust the period to always be greater than the minimum.

calculate()

Calculates the next datetime the message is going to be sent.

defer(dt: datetime)

Defers advertising until dt This should be used for overriding the normal next datetime the message was supposed to be sent on.

get() datetime

Returns the next datetime the message is going to be sent.

DaysOfWeekPeriod

class daf.message.messageperiod.DaysOfWeekPeriod(days: list[Literal['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']], time: time, next_send_time: timedelta | datetime | None = None)

Represents a period that will send on days at specific time.

E. g., parameters days=["Mon", "Wed"] and time=time(hour=12, minute=0) produce a behavior that will send a message every Monday and Wednesday at 12:00.

Parameters:
  • days (list[Literal["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]]) – List of day abbreviations on which the message will be sent.

  • time (datetime.time) – The time on which the message will be sent (every day of days).

  • next_send_time (datetime | timedelta) – Represents the time at which the message should first be sent. Use datetime to specify the exact date and time at which the message should start being sent. Use timedelta to specify how soon (after creation of the object) the message should start being sent.

Raises:

ValueError – The days parameter was an empty list.

calculate()

Calculates the next datetime the message is going to be sent.

adjust(minimum: timedelta) None

Adjust the period to always be greater than the minimum.

defer(dt: datetime)

Defers advertising until dt This should be used for overriding the normal next datetime the message was supposed to be sent on.

get() datetime

Returns the next datetime the message is going to be sent.

DailyPeriod

class daf.message.messageperiod.DailyPeriod(time: time, next_send_time: timedelta | datetime | None = None)

Represents a daily send period. Messages will be sent every day at time.

Parameters:
  • time (time) – The time on which the message will be sent.

  • next_send_time (datetime | timedelta) – Represents the time at which the message should first be sent. Use datetime to specify the exact date and time at which the message should start being sent. Use timedelta to specify how soon (after creation of the object) the message should start being sent.

adjust(minimum: timedelta) None

Adjust the period to always be greater than the minimum.

calculate()

Calculates the next datetime the message is going to be sent.

defer(dt: datetime)

Defers advertising until dt This should be used for overriding the normal next datetime the message was supposed to be sent on.

get() datetime

Returns the next datetime the message is going to be sent.

NamedDayOfYearPeriod

class daf.message.messageperiod.NamedDayOfYearPeriod(time: time, day: Literal['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], week: Literal[1, 2, 3, 4, 5], month: Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], next_send_time: timedelta | datetime | None = None)

Added in version 4.1.

This period type enables messages to be sent on specific week and day of a month each year on a specific time.

E.g., each year on second Monday in December at 12 noon (example below).

Parameters:
  • time (time) – The time at which to send.

  • day ('Mon'-'Sun') – The day of week when to send.

  • week (int) – The week number of which to send. E.g., 1 for 1st week, 2 for second week.

  • month (1 - 12) – The month in which to send.

  • next_send_time (datetime | timedelta) – Represents the time at which the message should first be sent. Use datetime to specify the exact date and time at which the message should start being sent. Use timedelta to specify how soon (after creation of the object) the message should start being sent.

Example

#  Every second Monday of December at 12:00.
 NamedDayOfYearPeriod(
    time=time(hour=12),  # Time
    day="Mon",  # Day (Monday)
    week=2,  # Which week (second monday)
    month=12  # Month (December)
)
calculate() datetime

Calculates the next datetime the message is going to be sent.

adjust(minimum: timedelta) None

Adjust the period to always be greater than the minimum.

defer(dt: datetime)

Defers advertising until dt This should be used for overriding the normal next datetime the message was supposed to be sent on.

get() datetime

Returns the next datetime the message is going to be sent.

NamedDayOfMonthPeriod

class daf.message.messageperiod.NamedDayOfMonthPeriod(time: time, day: Literal['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], week: Literal[1, 2, 3, 4, 5], next_send_time: timedelta | datetime | None = None)

Added in version 4.1.

This period type enables messages to be sent on specific week and day each month at a specific time.

E.g., each year on second Monday in December at 12 noon (example below).

Parameters:
  • time (time) – The time at which to send.

  • day ('Mon'-'Sun') – The day of week when to send.

  • week (int) – The week number of which to send. E.g., 1 for 1st week, 2 for second week.

  • next_send_time (datetime | timedelta) – Represents the time at which the message should first be sent. Use datetime to specify the exact date and time at which the message should start being sent. Use timedelta to specify how soon (after creation of the object) the message should start being sent.

Example

#  Second Monday of every month at 12:00.
 NamedDayOfMonthPeriod(
    time=time(hour=12),  # Time
    day="Mon",  # Day (Monday)
    week=2,  # Which week (second monday)
)
calculate() datetime

Calculates the next datetime the message is going to be sent.

adjust(minimum: timedelta) None

Adjust the period to always be greater than the minimum.

defer(dt: datetime)

Defers advertising until dt This should be used for overriding the normal next datetime the message was supposed to be sent on.

get() datetime

Returns the next datetime the message is going to be sent.