Decorators¶
exactly_once¶
django_periodic_tasks.decorators.exactly_once(func)Decorator ensuring a scheduled task runs at most once per invocation.
When the scheduler creates a TaskExecution row and passes its ID via
the _periodic_tasks_execution_id keyword argument, this decorator will:
- Pop
_periodic_tasks_execution_idfrom kwargs. - Lock the
TaskExecutionrow withSELECT FOR UPDATE. - Run the wrapped function only if the row’s status is
PENDING. - Mark the row
COMPLETEDon success.
If _periodic_tasks_execution_id is absent (e.g. manual invocation), the wrapped
function runs normally without any execution-permit logic.