Locking
Overview
Locks prevent concurrent or overly frequent operations that could overload the database or trigger duplicate runners.
ActionScheduler_Lock defines the lock interface, and ActionScheduler_OptionLock is the default implementation.
Lock lifecycle
- Acquire:
ActionScheduler_Lock::set( $lock_type ) - Check:
ActionScheduler_Lock::is_locked( $lock_type ) - Expiry:
ActionScheduler_Lock::get_expiration( $lock_type ) - Duration:
ActionScheduler_Lock::get_duration( $lock_type )(default 60 seconds)
Default lock class
ActionScheduler_Lock::instance() instantiates the lock class using:
- Filter:
action_scheduler_lock_class(defaultActionScheduler_OptionLock)
Default lock duration
ActionScheduler_Lock::get_duration() uses:
- Filter:
action_scheduler_lock_duration(defaultMINUTE_IN_SECONDS)
Option-based lock implementation
ActionScheduler_OptionLock stores lock values in wp_options:
- Key:
action_scheduler_lock_{lock_type} - Value:
uniqid() . '|' . ( time() + duration )
The lock is acquired using an atomic update of the option value, ensuring a lock cannot be stolen if another process updated it first.
Async request lock usage
The queue runner uses a lock of type async-request-runner to ensure async dispatch runs at most once per lock duration during shutdown requests.
Hooks & Filters
Filters
action_scheduler_lock_classaction_scheduler_lock_duration