Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Static Public Member Functions | Static Protected Member Functions | List of all members
core\task\manager Class Reference

Collection of task related methods. More...

Static Public Member Functions

static adhoc_task_complete (adhoc_task $task)
 This function indicates that an adhoc task was completed successfully. More...
 
static adhoc_task_failed (adhoc_task $task)
 This function indicates that an adhoc task was not completed successfully and should be retried. More...
 
static adhoc_task_from_record ($record)
 Utility method to create an adhoc task from a DB record. More...
 
static clear_fail_delay (scheduled_task $task)
 Clears the fail delay for the given task and updates its next run time based on the schedule. More...
 
static clear_static_caches ()
 This function is used to indicate that any long running cron processes should exit at the next opportunity and restart. More...
 
static configure_scheduled_task (scheduled_task $task)
 Change the default configuration for a scheduled task. More...
 
static ensure_adhoc_task_qos (array $records)
 Ensure quality of service for the ad hoc task queue. More...
 
static get_adhoc_tasks ($classname)
 This function load the adhoc tasks for a given classname. More...
 
static get_all_scheduled_tasks ()
 This function will return a list of all the scheduled tasks that exist in the database. More...
 
static get_default_scheduled_task ($classname, $expandr=true)
 This function load the default scheduled task details for a given classname. More...
 
static get_next_adhoc_task ($timestart, $checklimits=true)
 This function will dispatch the next adhoc task in the queue. More...
 
static get_next_scheduled_task ($timestart)
 This function will dispatch the next scheduled task in the queue. More...
 
static get_scheduled_task ($classname)
 This function load the scheduled task details for a given classname. More...
 
static is_runnable ()
 Returns if Moodle have access to PHP CLI binary or not. More...
 
static load_default_scheduled_tasks_for_component ($componentname, $expandr=true)
 Given a component name, will load the list of tasks in the db/tasks.php file for that component. More...
 
static load_scheduled_tasks_for_component ($componentname)
 Given a component name, will load the list of tasks from the scheduled_tasks table for that component. More...
 
static queue_adhoc_task (adhoc_task $task, $checkforexisting=false)
 Queue an adhoc task to run in the background. More...
 
static record_from_adhoc_task ($task)
 Utility method to create a DB record from an adhoc task. More...
 
static record_from_scheduled_task ($task)
 Utility method to create a DB record from a scheduled task. More...
 
static reschedule_or_queue_adhoc_task (adhoc_task $task)
 Schedule a new task, or reschedule an existing adhoc task which has matching data. More...
 
static reset_scheduled_tasks_for_component ($componentname)
 Update the database to contain a list of scheduled task for a component. More...
 
static run_from_cli (\core\task\task_base $task)
 Executes a cron from web invocation using PHP CLI. More...
 
static scheduled_task_complete (scheduled_task $task)
 This function indicates that a scheduled task was completed successfully and should be rescheduled. More...
 
static scheduled_task_failed (scheduled_task $task)
 This function indicates that a scheduled task was not completed successfully and should be retried. More...
 
static scheduled_task_from_record ($record, $expandr=true)
 Utility method to create a task from a DB record. More...
 
static static_caches_cleared_since ($starttime)
 Return true if the static caches have been cleared since $starttime. More...
 

Static Protected Member Functions

static find_php_cli_path ()
 Find the path of PHP CLI binary. More...
 
static get_canonical_class_name ($taskorstring)
 Gets class name for use in database table. More...
 
static get_concurrent_task_lock (adhoc_task $task)
 Gets the concurrent lock required to run an adhoc task. More...
 
static get_queued_adhoc_task_record ($task)
 Checks if the task with the same classname, component and customdata is already scheduled. More...
 
static task_is_scheduled ($task)
 Checks if the task with the same classname, component and customdata is already scheduled. More...
 

Detailed Description

Collection of task related methods.

Some locking rules for this class: All changes to scheduled tasks must be protected with both - the global cron lock and the lock for the specific scheduled task (in that order). Locks must be released in the reverse order.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ adhoc_task_complete()

static core\task\manager::adhoc_task_complete ( adhoc_task  $task)
static

This function indicates that an adhoc task was completed successfully.

Parameters
core::task::adhoc_task$task

◆ adhoc_task_failed()

static core\task\manager::adhoc_task_failed ( adhoc_task  $task)
static

This function indicates that an adhoc task was not completed successfully and should be retried.

Parameters
core::task::adhoc_task$task

◆ adhoc_task_from_record()

static core\task\manager::adhoc_task_from_record (   $record)
static

Utility method to create an adhoc task from a DB record.

Parameters
stdClass$record
Return values
core::task::adhoc_task

◆ clear_fail_delay()

static core\task\manager::clear_fail_delay ( scheduled_task  $task)
static

Clears the fail delay for the given task and updates its next run time based on the schedule.

Parameters
scheduled_task$taskTask to reset
Exceptions
dml_exceptionIf there is a database error

◆ clear_static_caches()

static core\task\manager::clear_static_caches ( )
static

This function is used to indicate that any long running cron processes should exit at the next opportunity and restart.

This is because something (e.g. DB changes) has changed and the static caches may be stale.

◆ configure_scheduled_task()

static core\task\manager::configure_scheduled_task ( scheduled_task  $task)
static

Change the default configuration for a scheduled task.

The list of scheduled tasks is taken from load_scheduled_tasks_for_component.

Parameters
core::task::scheduled_task$task- The new scheduled task information to store.
Return values
boolean- True if the config was saved.

◆ ensure_adhoc_task_qos()

static core\task\manager::ensure_adhoc_task_qos ( array  $records)
static

Ensure quality of service for the ad hoc task queue.

This reshuffles the adhoc tasks queue to balance by type to ensure a level of quality of service per type, while still maintaining the relative order of tasks queued by timestamp.

Parameters
array$recordsarray of task records
array$recordsarray of same task records shuffled

◆ find_php_cli_path()

static core\task\manager::find_php_cli_path ( )
staticprotected

Find the path of PHP CLI binary.

Return values
string|falseThe PHP CLI executable PATH

◆ get_adhoc_tasks()

static core\task\manager::get_adhoc_tasks (   $classname)
static

This function load the adhoc tasks for a given classname.

Parameters
string$classname
Return values
core::task::adhoc_task[]

◆ get_all_scheduled_tasks()

static core\task\manager::get_all_scheduled_tasks ( )
static

This function will return a list of all the scheduled tasks that exist in the database.

Return values
core::task::scheduled_task[]

◆ get_canonical_class_name()

static core\task\manager::get_canonical_class_name (   $taskorstring)
staticprotected

Gets class name for use in database table.

Always begins with a .

Parameters
string | task_base$taskorstringTask object or a string

◆ get_concurrent_task_lock()

static core\task\manager::get_concurrent_task_lock ( adhoc_task  $task)
staticprotected

Gets the concurrent lock required to run an adhoc task.

Parameters
adhoc_task$taskThe task to obtain the lock for
Return values
core::lock::lockThe lock if one was obtained successfully
Exceptions
coding_exception

◆ get_default_scheduled_task()

static core\task\manager::get_default_scheduled_task (   $classname,
  $expandr = true 
)
static

This function load the default scheduled task details for a given classname.

Parameters
string$classname
bool$expandr- if true (default) an 'R' value in a time is expanded to an appropriate int. If false, they are left as 'R'
Return values
core::task::scheduled_task|false

◆ get_next_adhoc_task()

static core\task\manager::get_next_adhoc_task (   $timestart,
  $checklimits = true 
)
static

This function will dispatch the next adhoc task in the queue.

The task will be handed out with an open lock - possibly on the entire cron process. Make sure you call either adhoc_task_failed or adhoc_task_complete to release the lock and reschedule the task.

Parameters
int$timestart
bool$checklimitsShould we check limits?
Return values
core::task::adhoc_taskor null if not found
Exceptions
moodle_exception

◆ get_next_scheduled_task()

static core\task\manager::get_next_scheduled_task (   $timestart)
static

This function will dispatch the next scheduled task in the queue.

The task will be handed out with an open lock - possibly on the entire cron process. Make sure you call either scheduled_task_failed or scheduled_task_complete to release the lock and reschedule the task.

Parameters
int$timestart- The start of the cron process - do not repeat any tasks that have been run more recently than this.
Return values
core::task::scheduled_taskor null
Exceptions
moodle_exception

◆ get_queued_adhoc_task_record()

static core\task\manager::get_queued_adhoc_task_record (   $task)
staticprotected

Checks if the task with the same classname, component and customdata is already scheduled.

Parameters
adhoc_task$task
Return values
bool

◆ get_scheduled_task()

static core\task\manager::get_scheduled_task (   $classname)
static

This function load the scheduled task details for a given classname.

Parameters
string$classname
Return values
core::task::scheduled_taskor false

◆ is_runnable()

static core\task\manager::is_runnable ( )
static

Returns if Moodle have access to PHP CLI binary or not.

Return values
bool

◆ load_default_scheduled_tasks_for_component()

static core\task\manager::load_default_scheduled_tasks_for_component (   $componentname,
  $expandr = true 
)
static

Given a component name, will load the list of tasks in the db/tasks.php file for that component.

Parameters
string$componentname- The name of the component to fetch the tasks for.
bool$expandr- if true (default) an 'R' value in a time is expanded to an appropriate int. If false, they are left as 'R'
Return values
core::task::scheduled_task[]- List of scheduled tasks for this component.

◆ load_scheduled_tasks_for_component()

static core\task\manager::load_scheduled_tasks_for_component (   $componentname)
static

Given a component name, will load the list of tasks from the scheduled_tasks table for that component.

Do not execute tasks loaded from this function - they have not been locked.

Parameters
string$componentname- The name of the component to load the tasks for.
Return values
core::task::scheduled_task[]

◆ queue_adhoc_task()

static core\task\manager::queue_adhoc_task ( adhoc_task  $task,
  $checkforexisting = false 
)
static

Queue an adhoc task to run in the background.

Parameters
core::task::adhoc_task$task- The new adhoc task information to store.
bool$checkforexisting- If set to true and the task with the same user, classname, component and customdata is already scheduled then it will not schedule a new task. Can be used only for ASAP tasks.
Return values
boolean- True if the config was saved.

◆ record_from_adhoc_task()

static core\task\manager::record_from_adhoc_task (   $task)
static

Utility method to create a DB record from an adhoc task.

Parameters
core::task::adhoc_task$task
Return values
stdClass

◆ record_from_scheduled_task()

static core\task\manager::record_from_scheduled_task (   $task)
static

Utility method to create a DB record from a scheduled task.

Parameters
core::task::scheduled_task$task
Return values
stdClass

◆ reschedule_or_queue_adhoc_task()

static core\task\manager::reschedule_or_queue_adhoc_task ( adhoc_task  $task)
static

Schedule a new task, or reschedule an existing adhoc task which has matching data.

Only a task matching the same user, classname, component, and customdata will be rescheduled. If these values do not match exactly then a new task is scheduled.

Parameters
core::task::adhoc_task$task- The new adhoc task information to store.
Since
Moodle 3.7

◆ reset_scheduled_tasks_for_component()

static core\task\manager::reset_scheduled_tasks_for_component (   $componentname)
static

Update the database to contain a list of scheduled task for a component.

The list of scheduled tasks is taken from @load_scheduled_tasks_for_component. Will throw exceptions for any errors.

Parameters
string$componentname- The frankenstyle component name.

◆ run_from_cli()

static core\task\manager::run_from_cli ( \core\task\task_base  $task)
static

Executes a cron from web invocation using PHP CLI.

Parameters
core::task::task_base$taskTask that be executed via CLI.
Return values
bool
Exceptions
moodle_exception

◆ scheduled_task_complete()

static core\task\manager::scheduled_task_complete ( scheduled_task  $task)
static

This function indicates that a scheduled task was completed successfully and should be rescheduled.

Parameters
core::task::scheduled_task$task

◆ scheduled_task_failed()

static core\task\manager::scheduled_task_failed ( scheduled_task  $task)
static

This function indicates that a scheduled task was not completed successfully and should be retried.

Parameters
core::task::scheduled_task$task

◆ scheduled_task_from_record()

static core\task\manager::scheduled_task_from_record (   $record,
  $expandr = true 
)
static

Utility method to create a task from a DB record.

Parameters
stdClass$record
bool$expandr- if true (default) an 'R' value in a time is expanded to an appropriate int. If false, they are left as 'R'
Return values
core::task::scheduled_task|false

◆ static_caches_cleared_since()

static core\task\manager::static_caches_cleared_since (   $starttime)
static

Return true if the static caches have been cleared since $starttime.

Parameters
int$starttimeThe time this process started.
Return values
booleanTrue if static caches need resetting.

◆ task_is_scheduled()

static core\task\manager::task_is_scheduled (   $task)
staticprotected

Checks if the task with the same classname, component and customdata is already scheduled.

Parameters
adhoc_task$task
Return values
bool

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