Scheduled tasks:

Moodle allows administrators to schedule routine tasks. These tasks are often referred to as “scheduled tasks” and run in the background. These scheduled tasks should run on a regular schedule however, administrators have the ability to change the scheduled task’s default schedule if required. Scheduled tasks will run as often as the cron is run in Moodle. It is recommended that the cron run every few minutes to get the maximum benefit from your scheduled tasks. This requires the task to do less work on each execution. The scheduled tasks essentially allow for task automation within Moodle.

Administrators can access the scheduled task for their site by navigating to:
Site administration > Server > Tasks > Scheduled Tasks

Scheduled tasks

Clicking the Edit icon allows you to edit the task schedule:

Edit scheduled tasks

You can specify the month, day, hour, and minute interval that this task will be run. Optionally, you can reset the task back to its default configuration or disable it entirely. In the example above, the scheduled task is set to run every 15 minutes.

The format of the fields that you can specify for the settings:

format of the fields

View task log:

Administrators can view a log of their scheduled task by navigating to:

Site administration > Server > Tasks > Tasks log

View task log

Manually executing tasks:

Administrators can manually run individual scheduled tasks via the “Run now” link under the scheduled tasks. The “Allow ‘Run now’ for scheduled tasks” setting must be enabled.

Site administration > Security > Site security settings

Manually executing tasks

In addition, the “Path to PHP CLI” setting must also be provided:

Site administration > Server > System paths

System paths run now

Task processing:

Administrators can define the additional configuration for scheduled tasks by navigating to:

Site administration > Server > Tasks > Task processing

Task processing

Executing task from the command line:

You can view a list of scheduled tasks by entering the following command:
php admin/cli/scheduled_task.php –list

Here is an example in which a specific scheduled task was executed from the command line:
php admin/cli/scheduled_task.php –execute=’\enrol_imsenterprise\task\cron_task’

For more information regarding scheduled tasks and the command line, please navigate to:
https://docs.moodle.org/39/en/Administration_via_command_line#Running_cron_via_command_lin 

Why should I consider scheduled task?

Scheduled tasks are a great way to keep the information on your site up to date. This includes user submissions, notifications, course progression, etc. Scheduled tasks are one factor that makes Moodle the leading LMS. Plugin developers should consider utilizing scheduled tasks in their development to create more immersive and consistent plugins.