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
| Attribute | Type | Description |
|---|
| nowfun | `Callable | None` |
| _app | `Celery | None` |
| 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. |
| tz | tzinfo | The timezone information retrieved from the associated Celery application's configuration. |
| utc_enabled | bool | A 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
| Name | Type | Description |
|---|
| nowfun | `Callable | None` = None |
| app | `Celery | None` = None |
Signature
def BaseSchedule(
nowfun: Callable | None = None,
app: Celery | None = None
) - > null
Parameters
| Name | Type | Description |
|---|
| nowfun | `Callable | None` = None |
| app | `Celery | None` = None |
Methods
now()
@classmethod
def now() - > datetime
Returns the current datetime using either the custom time source or the application's default clock.
Returns
| Type | Description |
|---|
datetime | The 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
| Name | Type | Description |
|---|
| last_run_at | datetime | The timestamp of the most recent successful execution. |
Returns
| Type | Description |
|---|
timedelta | The 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
| Name | Type | Description |
|---|
| last_run_at | datetime | The timestamp of the most recent successful execution. |
Returns
| Type | Description |
|---|
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
| Name | Type | Description |
|---|
| dt | datetime | The datetime object to be converted or localized. |
| naive_as_utc | bool = True | If True, treats naive datetime objects as UTC before conversion. |
Returns
| Type | Description |
|---|
datetime | A 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
| Type | Description |
|---|
[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
| Type | Description |
|---|
tzinfo | The 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
| Type | Description |
|---|
bool | True 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
| Name | Type | Description |
|---|
| dt | datetime | The datetime object to potentially localize. |
Returns
| Type | Description |
|---|
datetime | The localized datetime object or the original datetime if UTC is enabled. |