WP-Cron Integration
Overview
ActionScheduler_QueueRunner integrates with WP-Cron by registering a custom schedule and a cron hook that runs the queue.
Schedule and hook registration
On ActionScheduler_QueueRunner::init():
- Registers a schedule:
- Filter:
cron_schedules - Schedule key:
every_minute - Interval: 60 seconds
- Filter:
- Ensures older scheduled hooks (without context) are removed:
- Unschedules
action_scheduler_run_queuewith no context args if present.
- Unschedules
- Schedules the queue runner:
- Hook:
action_scheduler_run_queue - Arguments:
array( 'WP Cron' ) - Schedule filter:
action_scheduler_run_schedule(defaultevery_minute)
- Hook:
- Hooks the queue runner method:
add_action( 'action_scheduler_run_queue', array( ActionScheduler_QueueRunner::instance(), 'run' ) )
Context handling
The run() method defaults its $context to WP Cron. WP-Cron runs pass 'WP Cron' as the context via the scheduled event arguments.
Spawn mechanism and async kickoff
WP-Cron handles the baseline schedule, but Action Scheduler can also trigger async requests to keep the queue moving (see async-request.md). The queue runner hooks into shutdown to determine if it should dispatch an async request.
Hooks & Filters
Filters
cron_schedules(used to registerevery_minute)action_scheduler_run_schedule(controls cron schedule for the queue runner)
Actions
action_scheduler_run_queue(the queue runner hook executed by WP-Cron)