Services

SchedulerServiceInterface

v1.0.0

WordPress 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.

Methods

public function schedule(string $hook, string $recurrence, array $args = []): void

Schedules a recurring background task.

public function unschedule(string $hook): void

Removes a scheduled hook.

public function scheduleOnce(string $hook, int $timestamp, array $args = []): void

Schedules a one-off task.

public function isScheduled(string $hook): bool

Checks 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);
}