periodic_task¶
- exception oslo_service.periodic_task.InvalidPeriodicTaskArg¶
Bases:
Exception- message = 'Unexpected argument for periodic task creation: %(arg)s.'¶
- class oslo_service.periodic_task.PeriodicTasks(conf)¶
Bases:
object- add_periodic_task(task)¶
Add a periodic task to the list of periodic tasks.
The task should already be decorated by @periodic_task.
- run_periodic_tasks(context, raise_on_error=False)¶
Tasks to be run at a periodic interval.
- run_periodic_tasks_in_parallel(context, raise_on_error=False, processes=None)¶
Run due periodic tasks in parallel using a spawn-based process pool.
Uses
oslo_service._multiprocessing.get_spawn_pool()to avoid deadlocks when the main process has threads holding locks (e.g. logging). Fork would inherit those locks in child processes; spawn starts fresh processes.The PeriodicTasks instance (
self) andcontextmust be picklable when using this method.- Parameters:
context – Passed to each periodic task.
raise_on_error – If True, re-raise the first task exception.
processes – Number of worker processes (None = use pool default).
- Returns:
Same as
run_periodic_tasks()(idle_for).- Raises:
UnsupportedBackendError – When the eventlet backend is active.
Task results are collected as workers complete (via
ready()), not strictly in submission order, so a slow task does not delay observing completions of faster tasks. While work remains, the parent sleeps briefly between polls (see_PARALLEL_RESULT_POLL_INTERVAL) instead of busy-waiting.
- oslo_service.periodic_task.list_opts()¶
Entry point for oslo-config-generator.
- oslo_service.periodic_task.periodic_task(*args, **kwargs)¶
Decorator to indicate that a method is a periodic task.
This decorator can be used in two ways:
Without arguments ‘@periodic_task’, this will be run on the default interval of 60 seconds.
With arguments: @periodic_task(spacing=N [, run_immediately=[True|False]] [, name=[None|”string”]) this will be run on approximately every N seconds. If this number is negative the periodic task will be disabled. If the run_immediately argument is provided and has a value of ‘True’, the first run of the task will be shortly after task scheduler starts. If run_immediately is omitted or set to ‘False’, the first time the task runs will be approximately N seconds after the task scheduler starts. If name is not provided, __name__ of function is used.