@@ -35,54 +35,54 @@ |
||
35 | 35 | * @since 7.0.0 |
36 | 36 | */ |
37 | 37 | interface IJob { |
38 | - /** |
|
39 | - * Run the background job with the registered argument |
|
40 | - * |
|
41 | - * @param IJobList $jobList The job list that manages the state of this job |
|
42 | - * @param ILogger|null $logger |
|
43 | - * @since 7.0.0 |
|
44 | - */ |
|
45 | - public function execute(IJobList $jobList, ILogger $logger = null); |
|
38 | + /** |
|
39 | + * Run the background job with the registered argument |
|
40 | + * |
|
41 | + * @param IJobList $jobList The job list that manages the state of this job |
|
42 | + * @param ILogger|null $logger |
|
43 | + * @since 7.0.0 |
|
44 | + */ |
|
45 | + public function execute(IJobList $jobList, ILogger $logger = null); |
|
46 | 46 | |
47 | - /** |
|
48 | - * @since 7.0.0 |
|
49 | - */ |
|
50 | - public function setId(int $id); |
|
47 | + /** |
|
48 | + * @since 7.0.0 |
|
49 | + */ |
|
50 | + public function setId(int $id); |
|
51 | 51 | |
52 | - /** |
|
53 | - * @since 7.0.0 |
|
54 | - */ |
|
55 | - public function setLastRun(int $lastRun); |
|
52 | + /** |
|
53 | + * @since 7.0.0 |
|
54 | + */ |
|
55 | + public function setLastRun(int $lastRun); |
|
56 | 56 | |
57 | - /** |
|
58 | - * @param mixed $argument |
|
59 | - * @since 7.0.0 |
|
60 | - */ |
|
61 | - public function setArgument($argument); |
|
57 | + /** |
|
58 | + * @param mixed $argument |
|
59 | + * @since 7.0.0 |
|
60 | + */ |
|
61 | + public function setArgument($argument); |
|
62 | 62 | |
63 | - /** |
|
64 | - * Get the id of the background job |
|
65 | - * This id is determined by the job list when a job is added to the list |
|
66 | - * |
|
67 | - * @return int |
|
68 | - * @since 7.0.0 |
|
69 | - */ |
|
70 | - public function getId(); |
|
63 | + /** |
|
64 | + * Get the id of the background job |
|
65 | + * This id is determined by the job list when a job is added to the list |
|
66 | + * |
|
67 | + * @return int |
|
68 | + * @since 7.0.0 |
|
69 | + */ |
|
70 | + public function getId(); |
|
71 | 71 | |
72 | - /** |
|
73 | - * Get the last time this job was run as unix timestamp |
|
74 | - * |
|
75 | - * @return int |
|
76 | - * @since 7.0.0 |
|
77 | - */ |
|
78 | - public function getLastRun(); |
|
72 | + /** |
|
73 | + * Get the last time this job was run as unix timestamp |
|
74 | + * |
|
75 | + * @return int |
|
76 | + * @since 7.0.0 |
|
77 | + */ |
|
78 | + public function getLastRun(); |
|
79 | 79 | |
80 | - /** |
|
81 | - * Get the argument associated with the background job |
|
82 | - * This is the argument that will be passed to the background job |
|
83 | - * |
|
84 | - * @return mixed |
|
85 | - * @since 7.0.0 |
|
86 | - */ |
|
87 | - public function getArgument(); |
|
80 | + /** |
|
81 | + * Get the argument associated with the background job |
|
82 | + * This is the argument that will be passed to the background job |
|
83 | + * |
|
84 | + * @return mixed |
|
85 | + * @since 7.0.0 |
|
86 | + */ |
|
87 | + public function getArgument(); |
|
88 | 88 | } |
@@ -32,62 +32,62 @@ |
||
32 | 32 | use OCP\ILogger; |
33 | 33 | |
34 | 34 | abstract class Job implements IJob { |
35 | - /** @var int */ |
|
36 | - protected $id; |
|
35 | + /** @var int */ |
|
36 | + protected $id; |
|
37 | 37 | |
38 | - /** @var int */ |
|
39 | - protected $lastRun; |
|
38 | + /** @var int */ |
|
39 | + protected $lastRun; |
|
40 | 40 | |
41 | - /** @var mixed */ |
|
42 | - protected $argument; |
|
41 | + /** @var mixed */ |
|
42 | + protected $argument; |
|
43 | 43 | |
44 | - public function execute(IJobList $jobList, ILogger $logger = null) { |
|
45 | - $jobList->setLastRun($this); |
|
46 | - if ($logger === null) { |
|
47 | - $logger = \OC::$server->getLogger(); |
|
48 | - } |
|
44 | + public function execute(IJobList $jobList, ILogger $logger = null) { |
|
45 | + $jobList->setLastRun($this); |
|
46 | + if ($logger === null) { |
|
47 | + $logger = \OC::$server->getLogger(); |
|
48 | + } |
|
49 | 49 | |
50 | - try { |
|
51 | - $jobStartTime = time(); |
|
52 | - $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']); |
|
53 | - $this->run($this->argument); |
|
54 | - $timeTaken = time() - $jobStartTime; |
|
50 | + try { |
|
51 | + $jobStartTime = time(); |
|
52 | + $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']); |
|
53 | + $this->run($this->argument); |
|
54 | + $timeTaken = time() - $jobStartTime; |
|
55 | 55 | |
56 | - $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']); |
|
57 | - $jobList->setExecutionTime($this, $timeTaken); |
|
58 | - } catch (\Throwable $e) { |
|
59 | - if ($logger) { |
|
60 | - $logger->logException($e, [ |
|
61 | - 'app' => 'core', |
|
62 | - 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')' |
|
63 | - ]); |
|
64 | - } |
|
65 | - } |
|
66 | - } |
|
56 | + $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']); |
|
57 | + $jobList->setExecutionTime($this, $timeTaken); |
|
58 | + } catch (\Throwable $e) { |
|
59 | + if ($logger) { |
|
60 | + $logger->logException($e, [ |
|
61 | + 'app' => 'core', |
|
62 | + 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')' |
|
63 | + ]); |
|
64 | + } |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - abstract protected function run($argument); |
|
68 | + abstract protected function run($argument); |
|
69 | 69 | |
70 | - public function setId(int $id) { |
|
71 | - $this->id = $id; |
|
72 | - } |
|
70 | + public function setId(int $id) { |
|
71 | + $this->id = $id; |
|
72 | + } |
|
73 | 73 | |
74 | - public function setLastRun(int $lastRun) { |
|
75 | - $this->lastRun = $lastRun; |
|
76 | - } |
|
74 | + public function setLastRun(int $lastRun) { |
|
75 | + $this->lastRun = $lastRun; |
|
76 | + } |
|
77 | 77 | |
78 | - public function setArgument($argument) { |
|
79 | - $this->argument = $argument; |
|
80 | - } |
|
78 | + public function setArgument($argument) { |
|
79 | + $this->argument = $argument; |
|
80 | + } |
|
81 | 81 | |
82 | - public function getId() { |
|
83 | - return $this->id; |
|
84 | - } |
|
82 | + public function getId() { |
|
83 | + return $this->id; |
|
84 | + } |
|
85 | 85 | |
86 | - public function getLastRun() { |
|
87 | - return $this->lastRun; |
|
88 | - } |
|
86 | + public function getLastRun() { |
|
87 | + return $this->lastRun; |
|
88 | + } |
|
89 | 89 | |
90 | - public function getArgument() { |
|
91 | - return $this->argument; |
|
92 | - } |
|
90 | + public function getArgument() { |
|
91 | + return $this->argument; |
|
92 | + } |
|
93 | 93 | } |
@@ -36,26 +36,26 @@ |
||
36 | 36 | * @package OC\BackgroundJob |
37 | 37 | */ |
38 | 38 | abstract class TimedJob extends Job { |
39 | - protected $interval = 0; |
|
39 | + protected $interval = 0; |
|
40 | 40 | |
41 | - /** |
|
42 | - * set the interval for the job |
|
43 | - * |
|
44 | - * @param int $interval |
|
45 | - */ |
|
46 | - public function setInterval($interval) { |
|
47 | - $this->interval = $interval; |
|
48 | - } |
|
41 | + /** |
|
42 | + * set the interval for the job |
|
43 | + * |
|
44 | + * @param int $interval |
|
45 | + */ |
|
46 | + public function setInterval($interval) { |
|
47 | + $this->interval = $interval; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * run the job if |
|
52 | - * |
|
53 | - * @param IJobList $jobList |
|
54 | - * @param ILogger|null $logger |
|
55 | - */ |
|
56 | - public function execute($jobList, ILogger $logger = null) { |
|
57 | - if ((time() - $this->lastRun) > $this->interval) { |
|
58 | - parent::execute($jobList, $logger); |
|
59 | - } |
|
60 | - } |
|
50 | + /** |
|
51 | + * run the job if |
|
52 | + * |
|
53 | + * @param IJobList $jobList |
|
54 | + * @param ILogger|null $logger |
|
55 | + */ |
|
56 | + public function execute($jobList, ILogger $logger = null) { |
|
57 | + if ((time() - $this->lastRun) > $this->interval) { |
|
58 | + parent::execute($jobList, $logger); |
|
59 | + } |
|
60 | + } |
|
61 | 61 | } |