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

@return \core\task\scheduled_task[]
185284
public static function get_all_scheduled_tasks() {
        global $DB;

        $records = $DB->get_records('task_scheduled', null, 'component, classname', '*', IGNORE_MISSING);
        $tasks = array();

        foreach ($records as $record) {
            $task = self::scheduled_task_from_record($record);
            // Safety check in case the task in the DB does not match a real class (maybe something was uninstalled).
            if ($task) {
                $tasks[] = $task;
            }
        }

        return $tasks;
    }
883946
private function getAvailableTasks()
    {
        $tasks = array_map(function ($task) {
            return substr($task, 0, -4);
        }, array_diff(scandir(__DIR__.'/../../Task'), array('.', '..')));

        sort($tasks);

        return $tasks;
    }
927290
public function listTask()
	{
		$query = $this->resolveModel();

		$properties = $query->getStructure()->getTableColumns($query->getTableName());
		$properties = $this->normalizeProperties($properties);

		$searches = array();

		// Build a list of incoming filters from
		// the propertes of the model
		foreach ($properties as $property => $type)
		{
			if ($property == $query->getPrimaryKey())
			{
				continue;
			}

			if ($type == 'text')
			{
				$searches[] = $property;
				continue;
			}

			if ($type == 'integer')
			{
				$dflt = null;

				// 'state' is a very commonly used field and we want
				// it to default to published entries
				if ($property == 'state')
				{
					$dflt = $query::STATE_PUBLISHED;
					if (User::authorise('core.manage', $this->_option))
					{
						$dflt = null;
					}
				}

				$filters[$property] = Request::getInt($property, $dflt);

				// 'access' is another commonly used field where we
				// want to control what values are actually allowed
				if ($property == 'access')
				{
					if (is_null($filters[$property]))
					{
						$filters[$property] = User::getAuthorisedViewLevels();
					}
				}
			}
			else
			{
				$filters[$property] = Request::getVar($property);
			}
		}

		$filters['sort'] = Request::getString('sort', $query->orderBy);
		$filters['sort_Dir'] = Request::getWord('sort_Dir', $query->orderDir);

		if (!isset($properties[$filters['sort']]))
		{
			$filters['sort'] = $query->orderBy;
		}

		if (!in_array($filters['sort_Dir'], array('asc', 'desc')))
		{
			$filters['sort_Dir'] = $query->orderDir;
		}

		foreach ($filters as $field => $value)
		{
			if ($field == 'sort' || $field == 'sort_Dir')
			{
				continue;
			}

			if (is_null($value))
			{
				continue;
			}

			if (is_array($value))
			{
				$query->whereIn($field, $value);
			}
			else
			{
				if ($properties[$field] == 'string' && !$value)
				{
					continue;
				}

				if ($properties[$field] == 'date' && !$value)
				{
					continue;
				}

				$query->whereEquals($field, $value);
			}
		}

		// Are searching for anything?
		if ($search = (string)Request::getString('search'))
		{
			foreach ($searches as $i => $property)
			{
				if ($i == 0)
				{
					$query->whereLike($property, $search, 1);
				}
				else
				{
					$query->orWhereLike($property, $search, 1);
				}
			}
			$query->resetDepth();
		}

		// Get a total record count
		$total = with(clone $query)->total();

		// Build the response
		$response = new stdClass;
		$response->records = array();
		$response->total = $total;

		if ($response->total)
		{
			$base = rtrim(Request::base(), '/');

			$rows = $query
				->order($filters['sort'], $filters['sort_Dir'])
				->paginated('limitstart', 'limit')
				->rows();

			foreach ($rows as $row)
			{
				$obj = $row->toObject();
				foreach ($properties as $property => $type)
				{
					if ($type == 'date')
					{
						if ($obj->$property && $obj->$property != '0000-00-00 00:00:00')
						{
							$obj->$property = with(new Date($obj->$property))->format('Y-m-d\TH:i:s\Z');
						}
					}
					if ($type == 'text')
					{
						unset($obj->$property);
					}
				}
				if (method_exists($row, 'link'))
				{
					$obj->url = str_replace('/api', '', $base . '/' . ltrim(Route::url($row->link()), '/'));
				}

				$response->records[] = $obj;
			}
		}

		$this->send($response);
	}
476006
public function getTasks($tasks, $throwException = false)
    {
        $data = $this->query($throwException);

        $ret = [];
        foreach ($tasks as $task) {
            $ret[$task->getId()] = $this->formatTask($task, $data);
        }

        return $ret;
    }
713612
public function listAction()
    {
        $this->performAccessChecks();

        $crons = $this->cronService->listCronsStatus();
        $cronRows = array();

        foreach ($crons as $cron) {
            $cronRows[] = array(
                'alias' => $cron->getAlias(),
                'queued' => $cron instanceof SmileCron
                    ? ($cron->getQueued() ? $cron->getQueued()->format('d-m-Y H:i') : false)
                    : false,
                'started' => $cron instanceof SmileCron ? ($cron->getStarted()
                    ? $cron->getStarted()->format('d-m-Y H:i') : false)
                    : false,
                'ended' => $cron instanceof SmileCron ? ($cron->getEnded()
                    ? $cron->getEnded()->format('d-m-Y H:i') : false)
                    : false,
                'status' => $cron instanceof SmileCron ? $cron->getStatus() : false
            );
        }

        return $this->render('SmileEzUICronBundle:cron:tab/status/list.html.twig', [
            'datas' => $cronRows
        ]);
    }
589153
protected function _scheduleVars() {
		global $argv;
		$path = $argv[2] . DS;
		$shellName = $argv[3];
		$taskName = $argv[4];

		if (isset($this->args[0]) && $this->hasMethod($this->args[0])) {
			$methodName = $this->args[0];
			array_shift($this->args);
		} else {
			$methodName = null;
		}

		$command = implode(' ', array_filter(array(
			'Console/cake',
			$shellName,
			$taskName,
			$methodName
		)));

		$arguments = $this->args;
		foreach ($this->params as $name => $value) {
			if (in_array($name, array(
						'scheduled',
						'scheduled-depends-on',
						'scheduled-wait-prev',
						'skip-unlogged',
						'scheduled-process-timeout'
							), true)) {
				continue;
			}
			if (is_bool($value) && $value) {
				$arguments[] = '--' . $name;
			} elseif (!is_bool($value)) {
				$arguments['--' . $name] = $value;
			}
		}

		$options = array(
			'timeout' => $this->params['scheduled-process-timeout'],
			'dependsOn' => empty($this->params['scheduled-depends-on']) ? array() : explode(',', $this->params['scheduled-depends-on'])
		);

		return array($command, $path, $arguments, $options);
	}
88870
public function scheduled_tasks_table($tasks) {
        global $CFG;

        $showloglink = \core\task\logmanager::has_log_report();

        $table = new html_table();
        $table->head = [
            get_string('name'),
            get_string('component', 'tool_task'),
            get_string('edit'),
            get_string('logs'),
            get_string('lastruntime', 'tool_task'),
            get_string('nextruntime', 'tool_task'),
            get_string('taskscheduleminute', 'tool_task'),
            get_string('taskschedulehour', 'tool_task'),
            get_string('taskscheduleday', 'tool_task'),
            get_string('taskscheduledayofweek', 'tool_task'),
            get_string('taskschedulemonth', 'tool_task'),
            get_string('faildelay', 'tool_task'),
            get_string('default', 'tool_task'),
        ];

        $table->attributes['class'] = 'admintable generaltable';
        $table->colclasses = [];

        if (!$showloglink) {
            // Hide the log links.
            $table->colclasses['3'] = 'hidden';
        }

        $data = array();
        $yes = get_string('yes');
        $no = get_string('no');
        $never = get_string('never');
        $asap = get_string('asap', 'tool_task');
        $disabledstr = get_string('taskdisabled', 'tool_task');
        $plugindisabledstr = get_string('plugindisabled', 'tool_task');
        $runnabletasks = tool_task\run_from_cli::is_runnable();
        foreach ($tasks as $task) {
            $customised = $task->is_customised() ? $no : $yes;
            if (empty($CFG->preventscheduledtaskchanges)) {
                $configureurl = new moodle_url('/admin/tool/task/scheduledtasks.php', array('action'=>'edit', 'task' => get_class($task)));
                $editlink = $this->action_icon($configureurl, new pix_icon('t/edit', get_string('edittaskschedule', 'tool_task', $task->get_name())));
            } else {
                $editlink = $this->render(new pix_icon('t/locked', get_string('scheduledtaskchangesdisabled', 'tool_task')));
            }

            $loglink = '';
            if ($showloglink) {
                $loglink = $this->action_icon(
                    \core\task\logmanager::get_url_for_task_class(get_class($task)),
                    new pix_icon('e/file-text', get_string('viewlogs', 'tool_task', $task->get_name())
                ));
            }

            $namecell = new html_table_cell($task->get_name() . "\n" . html_writer::tag('span', '\\'.get_class($task),
                array('class' => 'task-class text-ltr')));
            $namecell->header = true;

            $component = $task->get_component();
            $plugininfo = null;
            list($type, $plugin) = core_component::normalize_component($component);
            if ($type === 'core') {
                $componentcell = new html_table_cell(get_string('corecomponent', 'tool_task'));
            } else {
                if ($plugininfo = core_plugin_manager::instance()->get_plugin_info($component)) {
                    $plugininfo->init_display_name();
                    $componentcell = new html_table_cell($plugininfo->displayname);
                } else {
                    $componentcell = new html_table_cell($component);
                }
            }

            $lastrun = $task->get_last_run_time() ? userdate($task->get_last_run_time()) : $never;
            $nextrun = $task->get_next_run_time();
            $disabled = false;
            if ($plugininfo && $plugininfo->is_enabled() === false && !$task->get_run_if_component_disabled()) {
                $disabled = true;
                $nextrun = $plugindisabledstr;
            } else if ($task->get_disabled()) {
                $disabled = true;
                $nextrun = $disabledstr;
            } else if ($nextrun > time()) {
                $nextrun = userdate($nextrun);
            } else {
                $nextrun = $asap;
            }

            $runnow = '';
            if ( ! $disabled && get_config('tool_task', 'enablerunnow') && $runnabletasks ) {
                $runnow = html_writer::div(html_writer::link(
                        new moodle_url('/admin/tool/task/schedule_task.php',
                            array('task' => get_class($task))),
                        get_string('runnow', 'tool_task')), 'task-runnow');
            }

            $clearfail = '';
            if ($task->get_fail_delay()) {
                $clearfail = html_writer::div(html_writer::link(
                        new moodle_url('/admin/tool/task/clear_fail_delay.php',
                                array('task' => get_class($task), 'sesskey' => sesskey())),
                        get_string('clear')), 'task-clearfaildelay');
            }

            $row = new html_table_row(array(
                        $namecell,
                        $componentcell,
                        new html_table_cell($editlink),
                        new html_table_cell($loglink),
                        new html_table_cell($lastrun . $runnow),
                        new html_table_cell($nextrun),
                        new html_table_cell($task->get_minute()),
                        new html_table_cell($task->get_hour()),
                        new html_table_cell($task->get_day()),
                        new html_table_cell($task->get_day_of_week()),
                        new html_table_cell($task->get_month()),
                        new html_table_cell($task->get_fail_delay() . $clearfail),
                        new html_table_cell($customised)));

            // Cron-style values must always be LTR.
            $row->cells[6]->attributes['class'] = 'text-ltr';
            $row->cells[7]->attributes['class'] = 'text-ltr';
            $row->cells[8]->attributes['class'] = 'text-ltr';
            $row->cells[9]->attributes['class'] = 'text-ltr';
            $row->cells[10]->attributes['class'] = 'text-ltr';

            if ($disabled) {
                $row->attributes['class'] = 'disabled';
            }
            $data[] = $row;
        }
        $table->data = $data;
        return html_writer::table($table);
    }
729521
public function getProjectTasks($project_id)
    {
        $result = $this->getProjectTaskAssignments($project_id);
        if ($result->isSuccess()) {
            $tasks = array();
            foreach ($result->data as $taskAssignment) {
                $taskResult = $this->getTask($taskAssignment->task_id);
                if ($taskResult->isSuccess()) {
                    $tasks[$taskResult->data->id] = $taskResult->data;
                }
            }
            $result->data = $tasks;
        }

        return $result;
    }
1268229
public function getAllTasks(){
        $rest = $this->getService( self::API_FS_TASK);
        $rest->GET();

        return $rest->getResultAsArray( models\FileSystem\FsTask::class);
    }
894084
public function fetchAll() {
        $crontab = $this->_exec('crontab -l');
        $crontab = trim($crontab);
        if (preg_match('/no crontab for/', $crontab)) {
            return null;
        } else {
            $cronjobs = explode("\n", $crontab);
            return $cronjobs;
        }
    }
461784
public function index() {
		$this->loadModel('Queue.QueueProcesses');
		$status = $this->QueueProcesses->status();

		$current = $this->QueuedJobs->getLength();
		$pendingDetails = $this->QueuedJobs->getPendingStats();
		$new = 0;
		foreach ($pendingDetails as $pendingDetail) {
			if ($pendingDetail['fetched'] || $pendingDetail['failed']) {
				continue;
			}
			$new++;
		}

		$data = $this->QueuedJobs->getStats();

		$taskFinder = new TaskFinder();
		$tasks = $taskFinder->allAppAndPluginTasks();

		$servers = $this->QueueProcesses->find()->distinct(['server'])->find('list', ['keyField' => 'server', 'valueField' => 'server'])->toArray();
		$this->set(compact('new', 'current', 'data', 'pendingDetails', 'status', 'tasks', 'servers'));
		$this->helpers[] = 'Tools.Format';
		$this->helpers[] = 'Tools.Time';
		$this->helpers[] = 'Tools.Text';
	}
961038
public function listArray() : Array
    {
        if( ! is_file($this->crontabCommands) )
        {
            return [];
        }

        return Arrays\RemoveElement::element(explode(EOL, file_get_contents($this->crontabCommands)), '');
    }
1059341
public static function reset_scheduled_tasks_for_component($componentname) {
        global $DB;
        $tasks = self::load_default_scheduled_tasks_for_component($componentname);
        $validtasks = array();

        foreach ($tasks as $taskid => $task) {
            $classname = self::get_canonical_class_name($task);

            $validtasks[] = $classname;

            if ($currenttask = self::get_scheduled_task($classname)) {
                if ($currenttask->is_customised()) {
                    // If there is an existing task with a custom schedule, do not override it.
                    continue;
                }

                // Update the record from the default task data.
                self::configure_scheduled_task($task);
            } else {
                // Ensure that the first run follows the schedule.
                $task->set_next_run_time($task->get_next_scheduled_time());

                // Insert the new task in the database.
                $record = self::record_from_scheduled_task($task);
                $DB->insert_record('task_scheduled', $record);
            }
        }

        // Delete any task that is not defined in the component any more.
        $sql = "component = :component";
        $params = array('component' => $componentname);
        if (!empty($validtasks)) {
            list($insql, $inparams) = $DB->get_in_or_equal($validtasks, SQL_PARAMS_NAMED, 'param', false);
            $sql .= ' AND classname ' . $insql;
            $params = array_merge($params, $inparams);
        }
        $DB->delete_records_select('task_scheduled', $sql, $params);
    }
751411
public function getChildren()
    {
        $objs = $this->caldavBackend->getSchedulingObjects($this->principalUri);
        $children = [];
        foreach ($objs as $obj) {
            //$obj['acl'] = $this->getACL();
            $obj['principaluri'] = $this->principalUri;
            $children[] = new SchedulingObject($this->caldavBackend, $obj);
        }

        return $children;
    }
805138
public function getAll(){
        $rest = $this->getService( self::API_DOWNLOAD);
        $rest->GET();

        return $rest->getResultAsArray( models\Download\Task::class);
    }
169797
public function getTaskList()
    {
        $propertyList = $this->_getEntityList('Tasks');
        $result = [];

        foreach ($propertyList as $properties) {
            $result[] = Task::createFromOptions($properties);
        }

        return $result;
    }
716193
public function serie()
    {
        $computedInSerie = array();

        foreach ($this->tasks as $task) {
            $task()->then(function($result) use (&$computedInSerie) {
                $computedInSerie[] = $result;
            }, function ($emptyResult) use (&$computedInSerie) {
                $computedInSerie[] = $emptyResult;
            });
        }

        return $computedInSerie;
    }