RedisScheduler

class beatdrop.schedulers.redis_scheduler.RedisScheduler

Bases: SingletonLockScheduler

Hold schedule entries in a Redis.

Uses Redis to store schedule entries and scheduler state. It is safe to run multiple RedisScheduler s simultaneously, as well as have many that are used as clients to read/write entries.

This scheduler does not implement the send method. This must be implemented before it can actually send tasks to the specified backend.

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.

  • lock_timeout (datetime.timedelta) – The time a scheduler does not refresh the scheduler lock before it is considered dead. Should be at least 3 times the max_interval.

  • redis_py_kwargs (Dict[str, Any]) – redis-py’s redis.Redis() key word arguments. Some of the client configuration items may be overwritten. https://redis-py.readthedocs.io/en/stable/connections.html#generic-client

delete(sched_entry: ScheduleEntry) None

Delete a schedule entry from the scheduler.

This does not delete default entries.

Parameters:

sched_entry (ScheduleEntry) – Scheduler entry to delete from the scheduler.

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:

ScheduleEntry

Raises:

beatdrop.exceptions.ScheduleEntryNotFound – The schedule entry could not be found.

list(page_size: int = 500) RedisScheduleEntryList

List schedule entries.

Parameters:

page_size (int, optional) – Redis suggested minimum page size, by default 500

Returns:

Iterator of all schedule entries. Automatically paginated redis results.

Return type:

RedisScheduleEntryList

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.

save(sched_entry: ScheduleEntry, read_only_attributes: bool = False) None

Save a new, or update an existing schedule entry in redis.

Parameters:
  • sched_entry (ScheduleEntry) – Schedule entry to create or update.

  • read_only_attributes (bool, optional) – If true, read only attributes are also saved to the DB. Clients should almost always leave this false, by default False

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.