diff options
author | Noveen Sachdeva <noveen.sachdeva@research.iiit.ac.in> | 2017-04-25 17:39:58 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-04-25 17:39:58 +0200 |
commit | 1b1f403a5da0a170480b7ff376cd28d1ac7a64e0 (patch) | |
tree | 97cdb615848bfc137f20387c7a632ccf9beaee44 /lib/private/BackgroundJob | |
parent | 8ef25a7628d44465d4777686227407f9a2067700 (diff) | |
download | nextcloud-server-1b1f403a5da0a170480b7ff376cd28d1ac7a64e0.tar.gz nextcloud-server-1b1f403a5da0a170480b7ff376cd28d1ac7a64e0.zip |
Add duration of last job execution to the table
Diffstat (limited to 'lib/private/BackgroundJob')
-rw-r--r-- | lib/private/BackgroundJob/Job.php | 10 | ||||
-rw-r--r-- | lib/private/BackgroundJob/JobList.php | 18 |
2 files changed, 25 insertions, 3 deletions
diff --git a/lib/private/BackgroundJob/Job.php b/lib/private/BackgroundJob/Job.php index 726c66ef5d7..cb9328f01b9 100644 --- a/lib/private/BackgroundJob/Job.php +++ b/lib/private/BackgroundJob/Job.php @@ -49,8 +49,18 @@ abstract class Job implements IJob { */ public function execute($jobList, ILogger $logger = null) { $jobList->setLastRun($this); + if ($logger === null) { + $logger = \OC::$server->getLogger(); + } + try { + $jobStartTime = time(); + $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']); $this->run($this->argument); + $timeTaken = time() - $jobStartTime; + + $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']); + $jobList->setExecutionTime($this, $timeTaken); } catch (\Exception $e) { if ($logger) { $logger->logException($e, [ diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index 0de5dfecc8b..b0c580290ed 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -275,7 +275,7 @@ class JobList implements IJobList { * * @param IJob $job */ - public function setLastJob($job) { + public function setLastJob(IJob $job) { $this->unlockJob($job); $this->config->setAppValue('backgroundjob', 'lastjob', $job->getId()); } @@ -285,7 +285,7 @@ class JobList implements IJobList { * * @param IJob $job */ - public function unlockJob($job) { + public function unlockJob(IJob $job) { $query = $this->connection->getQueryBuilder(); $query->update('jobs') ->set('reserved_at', $query->expr()->literal(0, IQueryBuilder::PARAM_INT)) @@ -310,11 +310,23 @@ class JobList implements IJobList { * * @param IJob $job */ - public function setLastRun($job) { + public function setLastRun(IJob $job) { $query = $this->connection->getQueryBuilder(); $query->update('jobs') ->set('last_run', $query->createNamedParameter(time(), IQueryBuilder::PARAM_INT)) ->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), IQueryBuilder::PARAM_INT))); $query->execute(); } + + /** + * @param IJob $job + * @param $timeTaken + */ + public function setExecutionTime(IJob $job, $timeTaken) { + $query = $this->connection->getQueryBuilder(); + $query->update('jobs') + ->set('execution_duration', $query->createNamedParameter($timeTaken, IQueryBuilder::PARAM_INT)) + ->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), IQueryBuilder::PARAM_INT))); + $query->execute(); + } } |