Services
SchedulerServiceInterface
v1.0.0WordPress cron abstraction for recurring and one-off background jobs.
Access
$ctx->scheduler()?->schedule('reports_sync', 'hourly');How To Use It
- Use it for background work that should not block page rendering, such as syncs, cleanup, and queued retries.
- Guard schedules with isScheduled() or unschedule() to avoid duplicate hooks during repeated boots or upgrades.
Works Well With
Methods
public function schedule(string $hook, string $recurrence, array $args = []): voidSchedules a recurring background task.
public function unschedule(string $hook): voidRemoves a scheduled hook.
public function scheduleOnce(string $hook, int $timestamp, array $args = []): voidSchedules a one-off task.
public function isScheduled(string $hook): boolChecks whether a hook is already scheduled.
Example
bootstrap.php
public function ensureSyncSchedule(SdkContext $ctx): void
{
if (! $ctx->scheduler()?->isScheduled('reports_sync')) {
$ctx->scheduler()?->schedule('reports_sync', 'hourly');
}
$ctx->scheduler()?->scheduleOnce('reports_cleanup', time() + 3600);
}