Merge branch 'MDL-58454-master' of git://github.com/junpataleta/moodle
[moodle.git] / lib / classes / task / task_base.php
blob05e68a5b36a8765a68e8547d538ba4b855db2bc1
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Abstract class for common properties of scheduled_task and adhoc_task.
20 * @package core
21 * @category task
22 * @copyright 2013 Damyon Wiese
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core\task;
27 /**
28 * Abstract class for common properties of scheduled_task and adhoc_task.
30 * @copyright 2013 Damyon Wiese
31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 abstract class task_base {
35 /** @var \core\lock\lock $lock - The lock controlling this task. */
36 private $lock = null;
38 /** @var \core\lock\lock $cronlock - The lock controlling the entire cron process. */
39 private $cronlock = null;
41 /** @var $string $component - The component this task belongs to. */
42 private $component = '';
44 /** @var bool $blocking - Does this task block the entire cron process. */
45 private $blocking = false;
47 /** @var int $faildelay - Exponentially increasing fail delay */
48 private $faildelay = 0;
50 /** @var int $nextruntime - When this task is due to run next */
51 private $nextruntime = 0;
53 /**
54 * Set the current lock for this task.
55 * @param \core\lock\lock $lock
57 public function set_lock(\core\lock\lock $lock) {
58 $this->lock = $lock;
61 /**
62 * Set the current lock for the entire cron process.
63 * @param \core\lock\lock $lock
65 public function set_cron_lock(\core\lock\lock $lock) {
66 $this->cronlock = $lock;
69 /**
70 * Get the current lock for this task.
71 * @return \core\lock\lock
73 public function get_lock() {
74 return $this->lock;
77 /**
78 * Get the next run time for this task.
79 * @return int timestamp
81 public function get_next_run_time() {
82 return $this->nextruntime;
85 /**
86 * Set the next run time for this task.
87 * @param int $nextruntime
89 public function set_next_run_time($nextruntime) {
90 $this->nextruntime = $nextruntime;
93 /**
94 * Get the current lock for the entire cron.
95 * @return \core\lock\lock
97 public function get_cron_lock() {
98 return $this->cronlock;
102 * Setter for $blocking.
103 * @param bool $blocking
105 public function set_blocking($blocking) {
106 $this->blocking = $blocking;
110 * Getter for $blocking.
111 * @return bool
113 public function is_blocking() {
114 return $this->blocking;
118 * Setter for $component.
119 * @param string $component
121 public function set_component($component) {
122 $this->component = $component;
126 * Getter for $component.
127 * @return string
129 public function get_component() {
130 return $this->component;
134 * Setter for $faildelay.
135 * @param int $faildelay
137 public function set_fail_delay($faildelay) {
138 $this->faildelay = $faildelay;
142 * Getter for $faildelay.
143 * @return int
145 public function get_fail_delay() {
146 return $this->faildelay;
150 * Do the job.
151 * Throw exceptions on errors (the job will be retried).
153 public abstract function execute();