|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Morris Jobke <[email protected]> |
|
4
|
|
|
* @author Robin Appelman <[email protected]> |
|
5
|
|
|
* @author Thomas Müller <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc. |
|
8
|
|
|
* @license AGPL-3.0 |
|
9
|
|
|
* |
|
10
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
12
|
|
|
* as published by the Free Software Foundation. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OC\BackgroundJob; |
|
25
|
|
|
|
|
26
|
|
|
use OCP\BackgroundJob\IJob; |
|
27
|
|
|
use OCP\ILogger; |
|
28
|
|
|
|
|
29
|
|
|
abstract class Job implements IJob { |
|
30
|
|
|
/** |
|
31
|
|
|
* @var int $id |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $id; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var int $lastRun |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $lastRun; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var mixed $argument |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $argument; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param JobList $jobList |
|
47
|
|
|
* @param ILogger $logger |
|
48
|
|
|
*/ |
|
49
|
15 |
|
public function execute($jobList, ILogger $logger = null) { |
|
50
|
15 |
|
$jobList->setLastRun($this); |
|
51
|
|
|
try { |
|
52
|
15 |
|
$this->run($this->argument); |
|
53
|
15 |
|
} catch (\Exception $e) { |
|
54
|
1 |
|
if ($logger) { |
|
55
|
1 |
|
$logger->error('Error while running background job: ' . $e->getMessage()); |
|
56
|
1 |
|
} |
|
57
|
|
|
} |
|
58
|
15 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
abstract protected function run($argument); |
|
61
|
|
|
|
|
62
|
19 |
|
public function setId($id) { |
|
63
|
19 |
|
$this->id = $id; |
|
64
|
19 |
|
} |
|
65
|
|
|
|
|
66
|
34 |
|
public function setLastRun($lastRun) { |
|
67
|
34 |
|
$this->lastRun = $lastRun; |
|
68
|
34 |
|
} |
|
69
|
|
|
|
|
70
|
34 |
|
public function setArgument($argument) { |
|
71
|
34 |
|
$this->argument = $argument; |
|
72
|
34 |
|
} |
|
73
|
|
|
|
|
74
|
19 |
|
public function getId() { |
|
75
|
19 |
|
return $this->id; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
1 |
|
public function getLastRun() { |
|
79
|
1 |
|
return $this->lastRun; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
5 |
|
public function getArgument() { |
|
83
|
5 |
|
return $this->argument; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|