class Scheduler (View source)

Class Scheduler

Simplified scheduler that provides four main methods:

  • command(): Run Bow console commands
  • task(): Run QueueTask classes
  • exec(): Run bash/shell commands
  • call(): Run closures/callbacks

Methods

void
__construct()

Scheduler constructor

static Scheduler
getInstance()

Get the Scheduler instance

setCache(Cache $cache)

Set the cache adapter for mutex locks

setLogger(callable $logger)

Set a custom logger callback

enableLogging(bool $enabled = true)

Enable or disable logging

command(string $command, array $parameters = [])

Schedule a Bow console command

task(string|QueueTask $task, array $parameters = [])

Schedule a QueueTask for execution

exec(string $command, array $parameters = [])

Schedule a shell/bash command

call(callable $callback, array $parameters = [])

Schedule a callback/closure for execution

array
getEvents()

Get all registered events

array
getDueEvents(DateTime|null $currentTime = null)

Get all due events

array
run(DateTime|null $currentTime = null)

Run all due events

array
runEvent(ScheduledEvent $event)

Run a single event

bool
acquireLock(ScheduledEvent $event)

Acquire a lock for overlap prevention

void
releaseLock(ScheduledEvent $event)

Release a lock for an event

void
log(string $message)

Log a message

clear()

Clear all registered events

void
start(int $sleepSeconds = 60)

Start the scheduler loop (for CLI daemon mode)

void
sleepUntilNextMinute(int $maxSleep = 60)

Sleep until the next minute boundary

static void
reset()

Reset the singleton instance (mainly for testing)

static mixed
__callStatic(string $name, array $arguments)

Magic method for static calls

Details

void __construct()

Scheduler constructor

Return Value

void

Exceptions

Exception

static Scheduler getInstance()

Get the Scheduler instance

Return Value

Scheduler

Scheduler setCache(Cache $cache)

Set the cache adapter for mutex locks

Parameters

Cache $cache

Return Value

Scheduler

Scheduler setLogger(callable $logger)

Set a custom logger callback

Parameters

callable $logger

Return Value

Scheduler

Scheduler enableLogging(bool $enabled = true)

Enable or disable logging

Parameters

bool $enabled

Return Value

Scheduler

Schedule command(string $command, array $parameters = [])

Schedule a Bow console command

Parameters

string $command

The Bow command (e.g., "migration:migrate", "clear:cache")

array $parameters

Optional parameters for the command

Return Value

Schedule

Schedule task(string|QueueTask $task, array $parameters = [])

Schedule a QueueTask for execution

Parameters

string|QueueTask $task

The QueueTask class name or instance

array $parameters

Parameters for instantiation (if class name provided)

Return Value

Schedule

Schedule exec(string $command, array $parameters = [])

Schedule a shell/bash command

Parameters

string $command

The shell command to execute

array $parameters

Optional arguments for the command

Return Value

Schedule

Schedule call(callable $callback, array $parameters = [])

Schedule a callback/closure for execution

Parameters

callable $callback

The callback to execute

array $parameters

Optional parameters to pass to the callback

Return Value

Schedule

array getEvents()

Get all registered events

Return Value

array

array getDueEvents(DateTime|null $currentTime = null)

Get all due events

Parameters

DateTime|null $currentTime

Return Value

array

array run(DateTime|null $currentTime = null)

Run all due events

Parameters

DateTime|null $currentTime

Return Value

array

protected array runEvent(ScheduledEvent $event)

Run a single event

Parameters

ScheduledEvent $event

Return Value

array

protected bool acquireLock(ScheduledEvent $event)

Acquire a lock for overlap prevention

Parameters

ScheduledEvent $event

Return Value

bool

protected void releaseLock(ScheduledEvent $event)

Release a lock for an event

Parameters

ScheduledEvent $event

Return Value

void

protected void log(string $message)

Log a message

Parameters

string $message

Return Value

void

Scheduler clear()

Clear all registered events

Return Value

Scheduler

void start(int $sleepSeconds = 60)

Start the scheduler loop (for CLI daemon mode)

Parameters

int $sleepSeconds

Return Value

void

protected void sleepUntilNextMinute(int $maxSleep = 60)

Sleep until the next minute boundary

Parameters

int $maxSleep

Return Value

void

static void reset()

Reset the singleton instance (mainly for testing)

Return Value

void

static mixed __callStatic(string $name, array $arguments)

Magic method for static calls

Parameters

string $name
array $arguments

Return Value

mixed