@@ -40,106 +40,106 @@ |
||
40 | 40 | */ |
41 | 41 | abstract class Job implements IJob { |
42 | 42 | |
43 | - /** @var int $id */ |
|
44 | - protected $id; |
|
45 | - |
|
46 | - /** @var int $lastRun */ |
|
47 | - protected $lastRun; |
|
48 | - |
|
49 | - /** @var mixed $argument */ |
|
50 | - protected $argument; |
|
51 | - |
|
52 | - /** @var ITimeFactory */ |
|
53 | - protected $time; |
|
54 | - |
|
55 | - /** |
|
56 | - * @since 15.0.0 |
|
57 | - */ |
|
58 | - public function __construct(ITimeFactory $time) { |
|
59 | - $this->time = $time; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * The function to prepare the execution of the job. |
|
64 | - * |
|
65 | - * |
|
66 | - * @param IJobList $jobList |
|
67 | - * @param ILogger|null $logger |
|
68 | - * |
|
69 | - * @since 15.0.0 |
|
70 | - */ |
|
71 | - public function execute(IJobList $jobList, ILogger $logger = null) { |
|
72 | - $jobList->setLastRun($this); |
|
73 | - if ($logger === null) { |
|
74 | - $logger = \OC::$server->getLogger(); |
|
75 | - } |
|
76 | - |
|
77 | - try { |
|
78 | - $jobStartTime = $this->time->getTime(); |
|
79 | - $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']); |
|
80 | - $this->run($this->argument); |
|
81 | - $timeTaken = $this->time->getTime() - $jobStartTime; |
|
82 | - |
|
83 | - $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']); |
|
84 | - $jobList->setExecutionTime($this, $timeTaken); |
|
85 | - } catch (\Exception $e) { |
|
86 | - if ($logger) { |
|
87 | - $logger->logException($e, [ |
|
88 | - 'app' => 'core', |
|
89 | - 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')' |
|
90 | - ]); |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @since 15.0.0 |
|
97 | - */ |
|
98 | - final public function setId(int $id) { |
|
99 | - $this->id = $id; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @since 15.0.0 |
|
104 | - */ |
|
105 | - final public function setLastRun(int $lastRun) { |
|
106 | - $this->lastRun = $lastRun; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @since 15.0.0 |
|
111 | - */ |
|
112 | - public function setArgument($argument) { |
|
113 | - $this->argument = $argument; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @since 15.0.0 |
|
118 | - */ |
|
119 | - final public function getId(): int { |
|
120 | - return $this->id; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @since 15.0.0 |
|
125 | - */ |
|
126 | - final public function getLastRun(): int { |
|
127 | - return $this->lastRun; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @since 15.0.0 |
|
132 | - */ |
|
133 | - public function getArgument() { |
|
134 | - return $this->argument; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * The actual function that is called to run the job |
|
139 | - * |
|
140 | - * @param $argument |
|
141 | - * |
|
142 | - * @since 15.0.0 |
|
143 | - */ |
|
144 | - abstract protected function run($argument); |
|
43 | + /** @var int $id */ |
|
44 | + protected $id; |
|
45 | + |
|
46 | + /** @var int $lastRun */ |
|
47 | + protected $lastRun; |
|
48 | + |
|
49 | + /** @var mixed $argument */ |
|
50 | + protected $argument; |
|
51 | + |
|
52 | + /** @var ITimeFactory */ |
|
53 | + protected $time; |
|
54 | + |
|
55 | + /** |
|
56 | + * @since 15.0.0 |
|
57 | + */ |
|
58 | + public function __construct(ITimeFactory $time) { |
|
59 | + $this->time = $time; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * The function to prepare the execution of the job. |
|
64 | + * |
|
65 | + * |
|
66 | + * @param IJobList $jobList |
|
67 | + * @param ILogger|null $logger |
|
68 | + * |
|
69 | + * @since 15.0.0 |
|
70 | + */ |
|
71 | + public function execute(IJobList $jobList, ILogger $logger = null) { |
|
72 | + $jobList->setLastRun($this); |
|
73 | + if ($logger === null) { |
|
74 | + $logger = \OC::$server->getLogger(); |
|
75 | + } |
|
76 | + |
|
77 | + try { |
|
78 | + $jobStartTime = $this->time->getTime(); |
|
79 | + $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']); |
|
80 | + $this->run($this->argument); |
|
81 | + $timeTaken = $this->time->getTime() - $jobStartTime; |
|
82 | + |
|
83 | + $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']); |
|
84 | + $jobList->setExecutionTime($this, $timeTaken); |
|
85 | + } catch (\Exception $e) { |
|
86 | + if ($logger) { |
|
87 | + $logger->logException($e, [ |
|
88 | + 'app' => 'core', |
|
89 | + 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')' |
|
90 | + ]); |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @since 15.0.0 |
|
97 | + */ |
|
98 | + final public function setId(int $id) { |
|
99 | + $this->id = $id; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @since 15.0.0 |
|
104 | + */ |
|
105 | + final public function setLastRun(int $lastRun) { |
|
106 | + $this->lastRun = $lastRun; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @since 15.0.0 |
|
111 | + */ |
|
112 | + public function setArgument($argument) { |
|
113 | + $this->argument = $argument; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @since 15.0.0 |
|
118 | + */ |
|
119 | + final public function getId(): int { |
|
120 | + return $this->id; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @since 15.0.0 |
|
125 | + */ |
|
126 | + final public function getLastRun(): int { |
|
127 | + return $this->lastRun; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @since 15.0.0 |
|
132 | + */ |
|
133 | + public function getArgument() { |
|
134 | + return $this->argument; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * The actual function that is called to run the job |
|
139 | + * |
|
140 | + * @param $argument |
|
141 | + * |
|
142 | + * @since 15.0.0 |
|
143 | + */ |
|
144 | + abstract protected function run($argument); |
|
145 | 145 | } |