Stud.IP  5.4
CronjobScheduler Class Reference

Public Member Functions

 registerTask ($task, $active=true)
 
 unregisterTask ($task_id)
 
 scheduleOnce ($task_id, $timestamp, $priority=CronjobSchedule::PRIORITY_NORMAL, $parameters=[])
 
 schedulePeriodic ($task_id, $minute=null, $hour=null, $day=null, $month=null, $day_of_week=null, $priority=CronjobSchedule::PRIORITY_NORMAL, $parameters=[])
 
 cancel ($schedule_id)
 
 cancelByTask ($task_id)
 
 run ()
 

Static Public Member Functions

static getInstance ()
 

Static Protected Attributes

static $instance = null
 

Member Function Documentation

◆ cancel()

cancel (   $schedule_id)

Cancels the provided schedule.

Parameters
String$schedule_idId of the schedule to be canceled

◆ cancelByTask()

cancelByTask (   $task_id)

Cancels all schedules of the provided task.

Parameters
String$task_idId of the task which schedules shall be canceled

◆ getInstance()

static getInstance ( )
static

Returns the scheduler object. Implements the singleton pattern to ensure that only one scheduler exists.

Returns
CronjobScheduler The scheduler object

◆ registerTask()

registerTask (   $task,
  $active = true 
)

Registers a new executable task.

Parameters
mixed$taskEither path of the task class filename (relative to Stud.IP root) or an instance of CronJob
bool$activeIndicates whether the task should be set active or not
Returns
String Id of the created task
Exceptions
InvalidArgumentExceptionwhen the task class file does not exist
RuntimeExceptionwhen task has already been registered

◆ run()

run ( )

Executes the available schedules if they are to be executed. This method can only be run once - even if one execution takes more than planned. This is ensured by a locking mechanism.

◆ scheduleOnce()

scheduleOnce (   $task_id,
  $timestamp,
  $priority = CronjobSchedule::PRIORITY_NORMAL,
  $parameters = [] 
)

Schedules a task for a single execution at the provided time.

Parameters
String$task_idThe id of the task to be executed
int$timestampWhen the task should be executed
String$priorityPriority of the execution (low, normal, high), defaults to normal
Array$parametersOptional parameters passed to the task
Returns
CronjobSchedule The generated schedule object.

◆ schedulePeriodic()

schedulePeriodic (   $task_id,
  $minute = null,
  $hour = null,
  $day = null,
  $month = null,
  $day_of_week = null,
  $priority = CronjobSchedule::PRIORITY_NORMAL,
  $parameters = [] 
)

Schedules a task for periodic execution with the provided schedule.

Parameters
String$task_idThe id of the task to be executed
mixed$minuteMinute part of the schedule:
  • null for "every minute" a.k.a. "don't care"
  • x < 0 for "every x minutes"
  • x >= 0 for "only at minute x"
mixed$hourHour part of the schedule:
  • null for "every hour" a.k.a. "don't care"
  • x < 0 for "every x hours"
  • x >= 0 for "only at hour x"
mixed$dayDay part of the schedule:
  • null for "every day" a.k.a. "don't care"
  • x < 0 for "every x days"
  • x > 0 for "only at day x"
mixed$monthMonth part of the schedule:
  • null for "every month" a.k.a. "don't care"
  • x < 0 for "every x months"
  • x > 0 for "only at month x"
mixed$day_of_weekDay of week part of the schedule:
  • null for "every day" a.k.a. "don't care"
  • 1 >= x >= 7 for "exactly at day of week x" (x starts with monday at 1 and ends with sunday at 7)
String$priorityPriority of the execution (low, normal, high), defaults to normal
Array$parametersOptional parameters passed to the task
Returns
CronjobSchedule The generated schedule object.

◆ unregisterTask()

unregisterTask (   $task_id)

Unregisters a previously registered task.

Parameters
String$task_idId of the task to be unregistered
Returns
CronjobScheduler to allow chaining
Exceptions
InvalidArgumentExceptionwhen no task with the given id exists

Field Documentation

◆ $instance

$instance = null
staticprotected

The documentation for this class was generated from the following file: