Scheduler (Base)¶
- class beatdrop.schedulers.scheduler.Scheduler¶
Bases:
object
Base Scheduler class.
All runnable schedulers must implement these methods:
run
- Run the scheduler.send
- Send a schedule entry to the task system.
All schedulers should implement these methods :
list
- List schedule entries.get
- Get a schedule entry.save
- Save a new or update an existing schedule entry.delete
- Delete a schedule entry.
See the docs on the methods for more information.
- Parameters:
max_interval (datetime.timedelta) – The maximum interval that the scheduler should sleep before waking up to check for due tasks.
sched_entry_types (Tuple[Type[ScheduleEntry]], default : (CrontabEntry, CrontabTZEntry, EventEntry, IntervalEntry)) – A list of valid schedule entry types for this scheduler. These are only stored in the scheduler, not externally.
default_sched_entries (List[ScheduleEntry], default : []) – Default list of schedule entries. In general these entries are not held in non-volatile storage so any metadata they hold will be lost if the scheduler fails. These entries are static. The keys cannot be overwritten or deleted.
- default_sched_entries: List[ScheduleEntry] | None = FieldInfo(default=[], extra={})¶
- delete(sched_entry: ScheduleEntry) None ¶
Delete a schedule entry from the scheduler.
- Parameters:
sched_entry (ScheduleEntry) – Scheduler entry to delete from the scheduler.
- Raises:
beatdrop.exceptions.MethodNotImplementedError –
delete
method not implemented.
- get(key: str) ScheduleEntry ¶
Retrieve a schedule entry by its key.
- Parameters:
key (str) – The schedule entry key.
- Returns:
The schedule entry with the matching key.
- Return type:
- Raises:
beatdrop.exceptions.MethodNotImplementedError –
get
method not implemented.
- list() Iterator[ScheduleEntry] ¶
List schedule entries.
- Returns:
List of schedule entries.
- Return type:
Iterator[ScheduleEntry]
- Raises:
beatdrop.exceptions.MethodNotImplementedError –
list
method not implemented.
- max_interval: timedelta¶
- classmethod max_interval_gte_one(max_interval: timedelta) timedelta ¶
- run(max_iterations: int = None) None ¶
Run the scheduler.
- Parameters:
max_iterations (int) –
default : None
The maximum number of iterations to run the scheduler. None is unlimited.
- Raises:
beatdrop.exceptions.MethodNotImplementedError – Must implement
run
method.
- save(sched_entry: ScheduleEntry, client_read_only: bool = False) None ¶
Save a new or update an existing schedule entry.
By default, read only attributes are not updated with
save
(suffixed with__
).- Parameters:
sched_entry (ScheduleEntry) – Schedule entry to add or update in scheduler.
client_read_only (bool) – Overwrite client read only fields?
False
will not overwrite client read only fields.True
will. This should almost always beFalse
, unless you are a scheduler, or you know what you’re doing.
- Raises:
beatdrop.exceptions.MethodNotImplementedError –
save
method not implemented.
- sched_entry_types: Tuple[Type[ScheduleEntry]] = FieldInfo(default=(<class 'beatdrop.entries.crontab_entry.CrontabEntry'>, <class 'beatdrop.entries.crontab_tz_entry.CrontabTZEntry'>, <class 'beatdrop.entries.event_entry.EventEntry'>, <class 'beatdrop.entries.interval_entry.IntervalEntry'>), extra={})¶
- send(sched_entry: ScheduleEntry) None ¶
Send a schedule entry to the task backend.
This should be used by the
run
method when a schedule is due. Subclasses can override this for common schedulers without changing the specifics of how a schedule runs. Send it to a queue, to celery etc.NOTE: for the reasons above the
send
method should not perform any actions against the state of the scheduler or schedule entries.- Parameters:
sched_entry (ScheduleEntry) – Schedule entry that will be sent to the task backend.
- Raises:
beatdrop.exceptions.MethodNotImplementedError – Must implement
send
method.