Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
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 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)
 This function load the default scheduled task details for a given classname. More...
 
static get_next_adhoc_task ($timestart)
 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 load_default_scheduled_tasks_for_component ($componentname)
 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 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)
 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 get_canonical_class_name ($taskorstring)
 Gets class name for use in database table. 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

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

◆ 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

◆ 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

◆ 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_default_scheduled_task()

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

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

Parameters
string$classname
Return values
core

◆ get_next_adhoc_task()

static core\task\manager::get_next_adhoc_task (   $timestart)
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 } or adhoc_task_complete to release the lock and reschedule the task.

Parameters
int$timestart
Return values
core

◆ 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 } 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

◆ 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

◆ load_default_scheduled_tasks_for_component()

static core\task\manager::load_default_scheduled_tasks_for_component (   $componentname)
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.
Return values
core

◆ 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

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

◆ 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)
static

Utility method to create a task from a DB record.

Parameters
stdClass$record
Return values
core

◆ 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: