@@ -30,72 +30,72 @@ |
||
| 30 | 30 | use OCP\ILogger; |
| 31 | 31 | |
| 32 | 32 | abstract class Job implements IJob { |
| 33 | - /** |
|
| 34 | - * @var int $id |
|
| 35 | - */ |
|
| 36 | - protected $id; |
|
| 33 | + /** |
|
| 34 | + * @var int $id |
|
| 35 | + */ |
|
| 36 | + protected $id; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var int $lastRun |
|
| 40 | - */ |
|
| 41 | - protected $lastRun; |
|
| 38 | + /** |
|
| 39 | + * @var int $lastRun |
|
| 40 | + */ |
|
| 41 | + protected $lastRun; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var mixed $argument |
|
| 45 | - */ |
|
| 46 | - protected $argument; |
|
| 43 | + /** |
|
| 44 | + * @var mixed $argument |
|
| 45 | + */ |
|
| 46 | + protected $argument; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param JobList $jobList |
|
| 50 | - * @param ILogger|null $logger |
|
| 51 | - */ |
|
| 52 | - public function execute($jobList, ILogger $logger = null) { |
|
| 53 | - $jobList->setLastRun($this); |
|
| 54 | - if ($logger === null) { |
|
| 55 | - $logger = \OC::$server->getLogger(); |
|
| 56 | - } |
|
| 48 | + /** |
|
| 49 | + * @param JobList $jobList |
|
| 50 | + * @param ILogger|null $logger |
|
| 51 | + */ |
|
| 52 | + public function execute($jobList, ILogger $logger = null) { |
|
| 53 | + $jobList->setLastRun($this); |
|
| 54 | + if ($logger === null) { |
|
| 55 | + $logger = \OC::$server->getLogger(); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - try { |
|
| 59 | - $jobStartTime = time(); |
|
| 60 | - $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']); |
|
| 61 | - $this->run($this->argument); |
|
| 62 | - $timeTaken = time() - $jobStartTime; |
|
| 58 | + try { |
|
| 59 | + $jobStartTime = time(); |
|
| 60 | + $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']); |
|
| 61 | + $this->run($this->argument); |
|
| 62 | + $timeTaken = time() - $jobStartTime; |
|
| 63 | 63 | |
| 64 | - $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']); |
|
| 65 | - $jobList->setExecutionTime($this, $timeTaken); |
|
| 66 | - } catch (\Throwable $e) { |
|
| 67 | - if ($logger) { |
|
| 68 | - $logger->logException($e, [ |
|
| 69 | - 'app' => 'core', |
|
| 70 | - 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')' |
|
| 71 | - ]); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 64 | + $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']); |
|
| 65 | + $jobList->setExecutionTime($this, $timeTaken); |
|
| 66 | + } catch (\Throwable $e) { |
|
| 67 | + if ($logger) { |
|
| 68 | + $logger->logException($e, [ |
|
| 69 | + 'app' => 'core', |
|
| 70 | + 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')' |
|
| 71 | + ]); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - abstract protected function run($argument); |
|
| 76 | + abstract protected function run($argument); |
|
| 77 | 77 | |
| 78 | - public function setId($id) { |
|
| 79 | - $this->id = $id; |
|
| 80 | - } |
|
| 78 | + public function setId($id) { |
|
| 79 | + $this->id = $id; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - public function setLastRun($lastRun) { |
|
| 83 | - $this->lastRun = $lastRun; |
|
| 84 | - } |
|
| 82 | + public function setLastRun($lastRun) { |
|
| 83 | + $this->lastRun = $lastRun; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - public function setArgument($argument) { |
|
| 87 | - $this->argument = $argument; |
|
| 88 | - } |
|
| 86 | + public function setArgument($argument) { |
|
| 87 | + $this->argument = $argument; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - public function getId() { |
|
| 91 | - return $this->id; |
|
| 92 | - } |
|
| 90 | + public function getId() { |
|
| 91 | + return $this->id; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - public function getLastRun() { |
|
| 95 | - return $this->lastRun; |
|
| 96 | - } |
|
| 94 | + public function getLastRun() { |
|
| 95 | + return $this->lastRun; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - public function getArgument() { |
|
| 99 | - return $this->argument; |
|
| 100 | - } |
|
| 98 | + public function getArgument() { |
|
| 99 | + return $this->argument; |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -57,17 +57,17 @@ |
||
| 57 | 57 | |
| 58 | 58 | try { |
| 59 | 59 | $jobStartTime = time(); |
| 60 | - $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']); |
|
| 60 | + $logger->debug('Run '.get_class($this).' job with ID '.$this->getId(), ['app' => 'cron']); |
|
| 61 | 61 | $this->run($this->argument); |
| 62 | 62 | $timeTaken = time() - $jobStartTime; |
| 63 | 63 | |
| 64 | - $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']); |
|
| 64 | + $logger->debug('Finished '.get_class($this).' job with ID '.$this->getId().' in '.$timeTaken.' seconds', ['app' => 'cron']); |
|
| 65 | 65 | $jobList->setExecutionTime($this, $timeTaken); |
| 66 | 66 | } catch (\Throwable $e) { |
| 67 | 67 | if ($logger) { |
| 68 | 68 | $logger->logException($e, [ |
| 69 | 69 | 'app' => 'core', |
| 70 | - 'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')' |
|
| 70 | + 'message' => 'Error while running background job (class: '.get_class($this).', arguments: '.print_r($this->argument, true).')' |
|
| 71 | 71 | ]); |
| 72 | 72 | } |
| 73 | 73 | } |