[Pkg-owncloud-commits] [owncloud] 20/28: Catch exceptions from background jobs and log them
David Prévot
taffit at moszumanska.debian.org
Sat Dec 7 02:33:32 UTC 2013
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit 46a4ad4f3c634c7aaedd90805221386d8284b651
Author: Robin Appelman <icewind at owncloud.com>
Date: Mon Dec 2 13:41:47 2013 +0100
Catch exceptions from background jobs and log them
---
cron.php | 6 ++++--
lib/private/backgroundjob/job.php | 22 ++++++++++++++++++++--
lib/private/backgroundjob/queuedjob.php | 5 +++--
lib/private/backgroundjob/timedjob.php | 6 +++---
4 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/cron.php b/cron.php
index 8e1a337..0d2c07b 100644
--- a/cron.php
+++ b/cron.php
@@ -50,6 +50,8 @@ try {
session_write_close();
+ $logger = \OC_Log::$object;
+
// Don't do anything if ownCloud has not been installed
if (!OC_Config::getValue('installed', false)) {
exit(0);
@@ -98,7 +100,7 @@ try {
$jobList = new \OC\BackgroundJob\JobList();
$jobs = $jobList->getAll();
foreach ($jobs as $job) {
- $job->execute($jobList);
+ $job->execute($jobList, $logger);
}
} else {
// We call cron.php from some website
@@ -109,7 +111,7 @@ try {
// Work and success :-)
$jobList = new \OC\BackgroundJob\JobList();
$job = $jobList->getNext();
- $job->execute($jobList);
+ $job->execute($jobList, $logger);
$jobList->setLastJob($job);
OC_JSON::success();
}
diff --git a/lib/private/backgroundjob/job.php b/lib/private/backgroundjob/job.php
index 49fbffb..2561659 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 1714182..799eac4 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 ae9f335..09e05f1 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);
}
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list