Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
|
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. | |
static | adhoc_task_failed (adhoc_task $task) |
This function indicates that an adhoc task was not completed successfully and should be retried. | |
static | adhoc_task_from_record ($record) |
Utility method to create an adhoc task from a DB record. | |
static | adhoc_task_starting (adhoc_task $task, int $time=0) |
Records that a adhoc task is starting to run. | |
static | clean_failed_adhoc_tasks () |
Clean up failed adhoc tasks. | |
static | cleanup_metadata () |
Cleanup stale task metadata. | |
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. | |
static | clear_static_caches () |
This function is used to indicate that any long running cron processes should exit at the next opportunity and restart. | |
static | configure_scheduled_task (scheduled_task $task) |
Change the default configuration for a scheduled task. | |
static | ensure_adhoc_task_qos (array $records) |
Ensure quality of service for the ad hoc task queue. | |
static | fail_running_task () |
This function will fail the currently running task, if there is one. | |
static | get_adhoc_task (int $taskid) |
This function will get an adhoc task by id. | |
static | get_adhoc_tasks (string $classname, bool $failedonly=false, bool $skiprunning=false) |
This function load the adhoc tasks for a given classname. | |
static | get_adhoc_tasks_summary () |
This function returns adhoc tasks summary per component classname. | |
static | get_all_scheduled_tasks () |
This function will return a list of all the scheduled tasks that exist in the database. | |
static | get_candidate_adhoc_tasks (int $timestart, int $limit, ?int $runmax, array $pertasklimits=[]) |
Return a list of candidate adhoc tasks to run. | |
static | get_canonical_class_name ($taskorstring) |
Gets class name for use in database table. | |
static | get_default_scheduled_task ($classname, $expandr=true) |
This function load the default scheduled task details for a given classname. | |
static | get_failed_adhoc_tasks (int $delay=0) |
This function will return a list of all adhoc tasks that have a faildelay. | |
static | get_next_adhoc_task (int $timestart, ?bool $checklimits=true, ?string $classname=null) |
This function will dispatch the next adhoc task in the queue. | |
static | get_next_scheduled_task ($timestart) |
This function will dispatch the next scheduled task in the queue. | |
static | get_running_tasks ($sort='') |
Gets a list of currently-running tasks. | |
static | get_scheduled_task ($classname) |
This function load the scheduled task details for a given classname. | |
static | is_runnable () |
Returns if Moodle have access to PHP CLI binary or not. | |
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. | |
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. | |
static | passthru_via_mtrace (string $command) |
This behaves similar to passthru but filters every line via the mtrace function so it can be post processed. | |
static | queue_adhoc_task (adhoc_task $task, $checkforexisting=false) |
Queue an adhoc task to run in the background. | |
static | record_from_adhoc_task ($task) |
Utility method to create a DB record from an adhoc task. | |
static | record_from_scheduled_task ($task) |
Utility method to create a DB record from a scheduled task. | |
static | reschedule_or_queue_adhoc_task (adhoc_task $task) |
Schedule a new task, or reschedule an existing adhoc task which has matching data. | |
static | reset_scheduled_tasks_for_component ($componentname) |
Update the database to contain a list of scheduled task for a component. | |
static | reset_state () |
Reset the state of the task manager. | |
static | run_adhoc_from_cli (int $taskid) |
Executes an ad hoc task from web invocation using PHP CLI. | |
static | run_all_adhoc_from_cli (?bool $failedonly=false, ?string $classname=null) |
Executes ad hoc tasks from web invocation using PHP CLI. | |
static | run_from_cli (scheduled_task $task) |
Executes a cron from web invocation using PHP CLI. | |
static | scheduled_task_complete (scheduled_task $task) |
This function indicates that a scheduled task was completed successfully and should be rescheduled. | |
static | scheduled_task_failed (scheduled_task $task) |
This function indicates that a scheduled task was not completed successfully and should be retried. | |
static | scheduled_task_from_record ($record, $expandr=true, $override=true) |
Utility method to create a task from a DB record. | |
static | scheduled_task_get_override_key (string $classname) |
Get the key within the scheduled tasks config object that for a classname. | |
static | scheduled_task_has_override (string $classname) |
This checks whether or not there is a value set in config for a scheduled task. | |
static | scheduled_task_starting (scheduled_task $task, int $time=0) |
Records that a scheduled task is starting to run. | |
static | static_caches_cleared_since ($starttime) |
Return true if the static caches have been cleared since $starttime. | |
Public Attributes | |
int const | ADHOC_TASK_FAILED_RETENTION = 4 * WEEKSECS |
Used to set the retention period for adhoc tasks that have failed and to be cleaned up. | |
int const | ADHOC_TASK_QUEUE_MODE_DISTRIBUTING = 0 |
Used to tell the adhoc task queue to fairly distribute tasks. | |
int const | ADHOC_TASK_QUEUE_MODE_FILLING = 1 |
Used to tell the adhoc task queue to try and fill unused capacity. | |
Static Public Attributes | |
static bool bool | $registeredshutdownhandler = false |
Used to tell if the manager's shutdown callback has been registered. | |
static task_base task_base | $runningtask = null |
$runningtask Used to tell what is the current running task in this process. | |
Static Protected Member Functions | |
static | find_php_cli_path () |
Find the path of PHP CLI binary. | |
static | get_concurrent_task_lock (adhoc_task $task) |
Gets the concurrent lock required to run an adhoc task. | |
static | get_queued_adhoc_task_record ($task) |
Checks if the task with the same classname, component and customdata is already scheduled. | |
static | get_record_with_config_overrides (\stdClass $record) |
For a given scheduled task record, this method will check to see if any overrides have been applied in config and return a copy of the record with any overridden values. | |
static | task_is_scheduled ($task) |
Checks if the task with the same classname, component and customdata is already scheduled. | |
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.
|
static |
This function indicates that an adhoc task was completed successfully.
core\task\adhoc_task | $task |
|
static |
This function indicates that an adhoc task was not completed successfully and should be retried.
core\task\adhoc_task | $task |
|
static |
Utility method to create an adhoc task from a DB record.
stdClass | $record |
core\task\adhoc_task |
moodle_exception |
|
static |
Records that a adhoc task is starting to run.
adhoc_task | $task | Task that is starting |
int | $time | Start time (leave blank for now) |
dml_exception | |
coding_exception |
|
static |
Clears the fail delay for the given task and updates its next run time based on the schedule.
scheduled_task | $task | Task to reset |
dml_exception | If there is a database error |
|
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.
|
static |
Change the default configuration for a scheduled task.
The list of scheduled tasks is taken from load_scheduled_tasks_for_component.
core\task\scheduled_task | $task | - The new scheduled task information to store. |
boolean | - True if the config was saved. |
|
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.
array | $records | array of task records |
array | $records | array of same task records shuffled |
|
staticprotected |
Find the path of PHP CLI binary.
string|false | The PHP CLI executable PATH |
|
static |
This function will get an adhoc task by id.
The task will be handed out with an open lock - possibly on the entire cron process. Make sure you call either {
int | $taskid |
core\task\adhoc_task|null |
moodle_exception |
|
static |
This function load the adhoc tasks for a given classname.
string | $classname | |
bool | $failedonly | |
bool | $skiprunning | do not return tasks that are in the running state |
array |
|
static |
This function returns adhoc tasks summary per component classname.
array |
|
static |
This function will return a list of all the scheduled tasks that exist in the database.
core\task\scheduled_task[] |
|
static |
Return a list of candidate adhoc tasks to run.
int | $timestart | Only return tasks where nextruntime is less than this value |
int | $limit | Limit the list to this many results |
int | null | $runmax | Only return tasks that have less than this value currently running |
array | $pertasklimits | An array of classname => limit specifying how many instance of a task may be returned |
array | Array of candidate tasks |
|
static |
Gets class name for use in database table.
Always begins with a .
string | task_base | $taskorstring | Task object or a string |
|
staticprotected |
Gets the concurrent lock required to run an adhoc task.
adhoc_task | $task | The task to obtain the lock for |
core\lock\lock | The lock if one was obtained successfully |
coding_exception |
|
static |
This function load the default scheduled task details for a given classname.
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' |
core\task\scheduled_task|false |
|
static |
This function will return a list of all adhoc tasks that have a faildelay.
int | $delay | filter how long the task has been delayed |
core\task\adhoc_task[] |
|
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.
int | $timestart | |
bool | $checklimits | Should we check limits? |
string | null | $classname | Return only task of this class |
core\task\adhoc_task|null |
moodle_exception |
|
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.
int | $timestart | - The start of the cron process - do not repeat any tasks that have been run more recently than this. |
core\task\scheduled_task | or null |
moodle_exception |
|
staticprotected |
Checks if the task with the same classname, component and customdata is already scheduled.
adhoc_task | $task |
stdClass|false |
|
staticprotected |
For a given scheduled task record, this method will check to see if any overrides have been applied in config and return a copy of the record with any overridden values.
The format of the config value is: $CFG->scheduled_tasks = array( '$classname' => array( 'schedule' => '* * * * *', 'disabled' => 1, ), );
Where $classname is the value of the task's classname, i.e. 'core\task\grade_cron_task'.
stdClass | $record | scheduled task record |
stdClass | scheduled task with any configured overrides |
|
static |
Gets a list of currently-running tasks.
string | $sort | Sorting method |
array | Array of scheduled and adhoc tasks |
dml_exception |
|
static |
This function load the scheduled task details for a given classname.
string | $classname |
core\task\scheduled_task | or false |
|
static |
Returns if Moodle have access to PHP CLI binary or not.
bool |
|
static |
Given a component name, will load the list of tasks in the db/tasks.php file for that component.
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' |
core\task\scheduled_task[] | - List of scheduled tasks for this component. |
|
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.
string | $componentname | - The name of the component to load the tasks for. |
core\task\scheduled_task[] |
|
static |
This behaves similar to passthru but filters every line via the mtrace function so it can be post processed.
string | $command | to run |
void |
|
static |
Queue an adhoc task to run in the background.
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. |
boolean | - True if the config was saved. |
|
static |
Utility method to create a DB record from an adhoc task.
core\task\adhoc_task | $task |
stdClass |
|
static |
Utility method to create a DB record from a scheduled task.
core\task\scheduled_task | $task |
stdClass |
|
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.
core\task\adhoc_task | $task | - The new adhoc task information to store. |
|
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.
string | $componentname | - The frankenstyle component name. |
|
static |
Executes an ad hoc task from web invocation using PHP CLI.
int | $taskid | Task to execute via CLI. |
moodle_exception |
|
static |
Executes ad hoc tasks from web invocation using PHP CLI.
bool | null | $failedonly | |
string | null | $classname | Task class to execute via CLI. |
moodle_exception |
|
static |
Executes a cron from web invocation using PHP CLI.
scheduled_task | $task | Task that be executed via CLI. |
bool |
moodle_exception |
|
static |
This function indicates that a scheduled task was completed successfully and should be rescheduled.
core\task\scheduled_task | $task |
|
static |
This function indicates that a scheduled task was not completed successfully and should be retried.
core\task\scheduled_task | $task |
|
static |
Utility method to create a task from a DB record.
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' |
bool | $override | - if true loads overridden settings from config. |
core\task\scheduled_task|false |
|
static |
Get the key within the scheduled tasks config object that for a classname.
string | $classname | the scheduled task classname to find |
string | the key if found, otherwise null |
|
static |
This checks whether or not there is a value set in config for a scheduled task.
string | $classname | Scheduled task's classname |
bool | true if there is an entry in config |
|
static |
Records that a scheduled task is starting to run.
scheduled_task | $task | Task that is starting |
int | $time | Start time (0 = current) |
dml_exception | If the task doesn't exist |
|
static |
Return true if the static caches have been cleared since $starttime.
int | $starttime | The time this process started. |
boolean | True if static caches need resetting. |
|
staticprotected |
Checks if the task with the same classname, component and customdata is already scheduled.
adhoc_task | $task |
bool |
int const core\task\manager::ADHOC_TASK_FAILED_RETENTION = 4 * WEEKSECS |
Used to set the retention period for adhoc tasks that have failed and to be cleaned up.
The number is in week unit. The default value is 4 weeks.