Skip to main content

BaseSchedule

This class serves as the abstract base for all schedule types, providing a common interface for determining when a task is due to run. It manages time-aware calculations, timezone conversions, and estimation logic for the next scheduled execution. Subclasses are expected to implement the core scheduling logic by overriding the is_due and remaining_estimate methods.

Attributes​

AttributeTypeDescription
nowfun`CallableNone`
_app`CeleryNone`
app[Celery](../app/base/celery.md?sid=celery_app_base_celery)The Celery application instance, which defaults to the current active application if not explicitly provided.
tztzinfoThe timezone information retrieved from the associated Celery application's configuration.
utc_enabledboolA boolean flag indicating whether UTC is enabled in the Celery application configuration.

Constructor​

Signature​

def BaseSchedule(
nowfun: Callable | None = None,
app: Celery | None = None
) - > null

Parameters​

NameTypeDescription
nowfun`CallableNone` = None
app`CeleryNone` = None

Signature​

def BaseSchedule(
nowfun: Callable | None = None,
app: Celery | None = None
) - > null

Parameters​

NameTypeDescription
nowfun`CallableNone` = None
app`CeleryNone` = None

Methods​


now()​

@classmethod
def now() - > datetime

Returns the current datetime using either the custom time source or the application's default clock.

Returns​

TypeDescription
datetimeThe current datetime object representing 'now'.

remaining_estimate()​

@classmethod
def remaining_estimate(
last_run_at: datetime
) - > timedelta

Calculates the time remaining until the next scheduled execution occurs.

Parameters​

NameTypeDescription
last_run_atdatetimeThe timestamp of the most recent successful execution.

Returns​

TypeDescription
timedeltaThe duration of time until the next run is due.

is_due()​

@classmethod
def is_due(
last_run_at: datetime
) - > tuple[bool, datetime]

Determines if the schedule is ready for execution based on the last run time.

Parameters​

NameTypeDescription
last_run_atdatetimeThe timestamp of the most recent successful execution.

Returns​

TypeDescription
tuple[bool, datetime]A tuple containing a boolean indicating if it is due and the number of seconds to wait until the next check.

maybe_make_aware()​

@classmethod
def maybe_make_aware(
dt: datetime,
naive_as_utc: bool = True
) - > datetime

Ensures a datetime object is timezone-aware using the schedule's configured timezone.

Parameters​

NameTypeDescription
dtdatetimeThe datetime object to be converted or localized.
naive_as_utcbool = TrueIf True, treats naive datetime objects as UTC before conversion.

Returns​

TypeDescription
datetimeA timezone-aware datetime object.

app()​

@classmethod
def app() - > [Celery](../app/base/celery.md?sid=celery_app_base_celery)

Retrieves the Celery application instance associated with this schedule, falling back to the current global app if none is set.

Returns​

TypeDescription
[Celery](../app/base/celery.md?sid=celery_app_base_celery)The active Celery application instance.

tz()​

@classmethod
def tz() - > tzinfo

Retrieves the timezone information from the associated Celery application.

Returns​

TypeDescription
tzinfoThe timezone object used for scheduling calculations.

utc_enabled()​

@classmethod
def utc_enabled() - > bool

Checks the application configuration to determine if UTC mode is active.

Returns​

TypeDescription
boolTrue if UTC is enabled in the application configuration, False otherwise.

to_local()​

@classmethod
def to_local(
dt: datetime
) - > datetime

Converts a datetime object to local time if UTC is not enabled in the application configuration.

Parameters​

NameTypeDescription
dtdatetimeThe datetime object to potentially localize.

Returns​

TypeDescription
datetimeThe localized datetime object or the original datetime if UTC is enabled.