Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

(no description)

File Size: 685 lines (27 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: cron  - X-Ref

Cron and adhoc task functionality.

run_main_process(?int $keepalive = null)   X-Ref
Execute cron tasks

param: int|null $keepalive The keepalive time for this cron run.

run_scheduled_tasks(int $startruntime,?int $startprocesstime = null,)   X-Ref
Execute all queued scheduled tasks, applying necessary concurrency limits and time limits.

param: int       $startruntime The time this run started.
param: null|int  $startprocesstime The time the process that owns this runner started.

run_adhoc_tasks(int $startruntime,$keepalive = 0,$checklimits = true,?int $startprocesstime = null,?int $maxtasks = null,?string $classname = null,)   X-Ref
Execute all queued adhoc tasks, applying necessary concurrency limits and time limits.

param: int     $startruntime The time this run started.
param: int     $keepalive Keep this public static function alive for N seconds and poll for new adhoc tasks.
param: bool    $checklimits Should we check limits?
param: null|int $startprocesstime The time this process started.
param: int|null $maxtasks Limit number of tasks to run`
param: null|string $classname Run only tasks of this class

run_adhoc_task(int $taskid)   X-Ref
Execute an adhoc task.

param: int       $taskid

run_failed_adhoc_tasks(?string $classname = null)   X-Ref
Execute all failed adhoc tasks.

param: string|null  $classname Run only tasks of this class

run_inner_scheduled_task(\core\task\task_base $task)   X-Ref
Shared code that handles running of a single scheduled task within the cron.

Not intended for calling directly outside of this library!

param: \core\task\task_base $task

run_inner_adhoc_task(\core\task\adhoc_task $task)   X-Ref
Shared code that handles running of a single adhoc task within the cron.

param: \core\task\adhoc_task $task

set_process_title(string $title)   X-Ref
Sets the process title

This makes it very easy for a sysadmin to immediately see what task
a cron process is running at any given moment.

param: string $title process status title

trace_time_and_memory()   X-Ref
Output some standard information during cron runs. Specifically current time
and memory usage. This method also does gc_collect_cycles() (before displaying
memory usage) to try to help PHP manage memory better.


prepare_core_renderer($restore = false)   X-Ref
Prepare the output renderer for the cron run.

This involves creating a new $PAGE, and $OUTPUT fresh for each task and prevents any one task from influencing
any other.

param: bool    $restore Whether to restore the original PAGE and OUTPUT

setup_user(?stdClass $user = null, ?stdClass $course = null, bool $leavepagealone = false)   X-Ref
Sets up a user and course environment in cron.

Note: This function is intended only for use in:
- the cron runner scripts
- individual tasks which extend the adhoc_task and scheduled_task classes
- unit tests related to tasks
- other parts of the cron/task system

Please note that this function stores cache data statically.
param: null|stdClass $user full user object, null means default cron user (admin)
param: null|stdClass $course full course record, null means $SITE
param: null|bool $leavepagealone If specified, stops it messing with global page object

reset_user_cache()   X-Ref
Resets the cache for the cron user used by `setup_user()`.