diff options
author | Robin Appelman <icewind@owncloud.com> | 2013-12-02 13:41:47 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2013-12-02 13:41:47 +0100 |
commit | 35bb6f7e3a4df325e594e1d206520e89014f2a42 (patch) | |
tree | 308e9dac501b7ed6ff50563bb553bbf052b80eb5 /lib/private/backgroundjob | |
parent | c2e83e635d0ad0fda4dbf9c89c06b45f59bc3b24 (diff) | |
download | nextcloud-server-35bb6f7e3a4df325e594e1d206520e89014f2a42.tar.gz nextcloud-server-35bb6f7e3a4df325e594e1d206520e89014f2a42.zip |
Catch exceptions from background jobs and log them
Diffstat (limited to 'lib/private/backgroundjob')
-rw-r--r-- | lib/private/backgroundjob/job.php | 22 | ||||
-rw-r--r-- | lib/private/backgroundjob/queuedjob.php | 5 | ||||
-rw-r--r-- | lib/private/backgroundjob/timedjob.php | 6 |
3 files changed, 26 insertions, 7 deletions
diff --git a/lib/private/backgroundjob/job.php b/lib/private/backgroundjob/job.php index 49fbffbd684..25616597504 100644 --- a/lib/private/backgroundjob/job.php +++ b/lib/private/backgroundjob/job.php @@ -9,16 +9,34 @@ namespace OC\BackgroundJob; abstract class Job { + /** + * @var int $id + */ protected $id; + + /** + * @var int $lastRun + */ protected $lastRun; + + /** + * @var mixed $argument + */ protected $argument; /** * @param JobList $jobList + * @param \OC\Log $logger */ - public function execute($jobList) { + public function execute($jobList, $logger = null) { $jobList->setLastRun($this); - $this->run($this->argument); + try { + $this->run($this->argument); + } catch (\Exception $e) { + if ($logger) { + $logger->error('Error while running background job: ' . $e->getMessage()); + } + } } abstract protected function run($argument); diff --git a/lib/private/backgroundjob/queuedjob.php b/lib/private/backgroundjob/queuedjob.php index 1714182820d..799eac47848 100644 --- a/lib/private/backgroundjob/queuedjob.php +++ b/lib/private/backgroundjob/queuedjob.php @@ -20,9 +20,10 @@ abstract class QueuedJob extends Job { * run the job, then remove it from the joblist * * @param JobList $jobList + * @param \OC\Log $logger */ - public function execute($jobList) { + public function execute($jobList, $logger = null) { $jobList->remove($this); - $this->run($this->argument); + parent::execute($jobList, $logger); } } diff --git a/lib/private/backgroundjob/timedjob.php b/lib/private/backgroundjob/timedjob.php index ae9f33505ab..09e05f1d846 100644 --- a/lib/private/backgroundjob/timedjob.php +++ b/lib/private/backgroundjob/timedjob.php @@ -31,11 +31,11 @@ abstract class TimedJob extends Job { * run the job if * * @param JobList $jobList + * @param \OC\Log $logger */ - public function execute($jobList) { + public function execute($jobList, $logger = null) { if ((time() - $this->lastRun) > $this->interval) { - $jobList->setLastRun($this); - $this->run($this->argument); + parent::execute($jobList, $logger); } } } |