This document describes the current stable version of Celery (5.7). For development docs, go here.
celery.beat¶
The periodic task scheduler.
- class celery.beat.BeatPidbox(service)[source]¶
Remote-control mailbox node for beat.
Binds a
celerybeat@hostnamenode to the samecelery.pidboxfanout exchange the workers use, so thatcelery inspect ping(optionally with--destination) also reaches beat.Only the
pingcommand is implemented; any other broadcast command is ignored silently, since replying with an error would pollute the output of worker-only commands likeinspect active.The node stops answering once the scheduler has not ticked for
max_tick_ageseconds. Staying silent is the only signal a probe can act on: celery inspect exits non-zero when no node replies, but an error reply still counts as a reply and leaves the exit status at zero.- fanout_support()[source]¶
Return
(supported, transport_name)for the read transport.Reads the transport’s declared capabilities, so no connection is opened and this is safe to call before starting the thread. The name comes back with the answer rather than from a second throwaway connection built to format the warning.
- first_connection_attempt¶
the first attempt is governed by broker_connection_retry_on_startup, later ones by broker_connection_retry.
- Type:
mirrors the worker
- property max_tick_age¶
Seconds a tick may be overdue before beat stops replying.
Falls back to twice the interval the scheduler actually settled on – which a scheduler class may choose itself, so it is not always
beat_max_loop_interval– withmin_tick_ageas a floor.0disables the check.The service records that interval on the main thread once the scheduler exists, because the scheduler is a lazy attribute and this runs on the consumer thread, which must not build it.
- min_tick_age = 60.0¶
floor for the derived
max_tick_age. A scheduler with a short loop interval (django-celery-beat’s is five seconds) would otherwise get a window so tight that one slow pass looks like a stall, and on a liveness probe that means restart loops.
- retry_interval = 5.0¶
seconds to pause before reconnecting after an established connection is lost. Establishing a connection is governed by
broker_connection_retryandbroker_connection_max_retriesinstead.
- celery.beat.EmbeddedService(app, max_interval=None, **kwargs)[source]¶
Return embedded clock service.
- Parameters:
thread (bool) – Run threaded instead of as a separate process. Uses
multiprocessingby default, if available.
- class celery.beat.PersistentScheduler(*args, **kwargs)[source]¶
Scheduler backed by
shelvedatabase.- property info¶
- known_suffixes = ('', '.db', '.dat', '.bak', '.dir')¶
- persistence = <module 'shelve' from '/home/docs/.asdf/installs/python/3.11.15/lib/python3.11/shelve.py'>¶
- property schedule¶
- class celery.beat.ScheduleEntry(name=None, task=None, last_run_at=None, total_run_count=None, schedule=None, args=(), kwargs=None, options=None, relative=False, app=None)[source]¶
An entry in the scheduler.
- Parameters:
- args = None¶
Positional arguments to apply.
- kwargs = None¶
Keyword arguments to apply.
- last_run_at = None¶
The time and date of when this task was last scheduled.
- name = None¶
The task name
- next(last_run_at=None)¶
Return new instance, with date and count fields updated.
- options = None¶
Task execution options.
- total_run_count = 0¶
Total number of times this task has been scheduled.
- class celery.beat.Scheduler(app, schedule=None, max_interval=None, Producer=None, lazy=False, sync_every_tasks=None, **kwargs)[source]¶
Scheduler for periodic tasks.
The celery beat program may instantiate this class multiple times for introspection purposes, but then with the
lazyargument set. It’s important for subclasses to be idempotent when this argument is set.- Parameters:
max_interval (int) – see
max_interval.lazy (bool) – Don’t set up the schedule.
- Entry¶
alias of
ScheduleEntry
- property connection¶
- property info¶
- logger = <Logger celery.beat (WARNING)>¶
- max_interval = 300¶
Maximum time to sleep between re-checking the schedule.
- populate_heap(event_t=<class 'celery.beat.event_t'>, heapify=<built-in function heapify>)[source]¶
Populate the heap with the data contained in the schedule.
- property producer¶
- property schedule¶
The schedule dict/shelve.
- sync_every = 180¶
How often to sync the schedule (3 minutes by default)
- sync_every_tasks = None¶
How many tasks can be called before a sync is forced.
- class celery.beat.Service(app, max_interval=None, schedule_filename=None, scheduler_cls=None, remote_control=None, hostname=None)[source]¶
Celery periodic task service.
- effective_max_interval¶
interval the scheduler settled on, recorded once it exists so the pidbox thread never has to build the lazy attribute.
- property scheduler¶
- scheduler_cls¶
alias of
PersistentScheduler