diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-02-14 23:11:10 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-02-14 23:11:10 +0100 |
commit | 750ffa82317a6538384a9680d3fe5bc4b0395c70 (patch) | |
tree | feb8113332fda566d4343451eda9b95b0015e41e /lib/public | |
parent | df282d9ef8e040833574fac5c5fd3cbbae1b3209 (diff) | |
parent | d6576c640c429d24a6329573c0dfaf99d82ac867 (diff) | |
download | nextcloud-server-750ffa82317a6538384a9680d3fe5bc4b0395c70.tar.gz nextcloud-server-750ffa82317a6538384a9680d3fe5bc4b0395c70.zip |
Merge pull request #7156 from owncloud/backgroundjob-public
Add the background job list to the public server container
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/backgroundjob.php | 14 | ||||
-rw-r--r-- | lib/public/backgroundjob/ijob.php | 42 | ||||
-rw-r--r-- | lib/public/backgroundjob/ijoblist.php | 77 | ||||
-rw-r--r-- | lib/public/iservercontainer.php | 7 |
4 files changed, 133 insertions, 7 deletions
diff --git a/lib/public/backgroundjob.php b/lib/public/backgroundjob.php index a7f54491dfa..bcaf6e35454 100644 --- a/lib/public/backgroundjob.php +++ b/lib/public/backgroundjob.php @@ -33,7 +33,7 @@ use \OC\BackgroundJob\JobList; /** * This class provides functions to register backgroundjobs in ownCloud * - * To create a new backgroundjob create a new class that inharits from either \OC\BackgroundJob\Job, + * To create a new backgroundjob create a new class that inherits from either \OC\BackgroundJob\Job, * \OC\BackgroundJob\QueuedJob or \OC\BackgroundJob\TimedJob and register it using * \OCP\BackgroundJob->registerJob($job, $argument), $argument will be passed to the run() function * of the job when the job is executed. @@ -73,7 +73,7 @@ class BackgroundJob { * @param mixed $argument */ public static function registerJob($job, $argument = null) { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $jobList->add($job, $argument); } @@ -99,7 +99,7 @@ class BackgroundJob { * key is string "$klass-$method", value is array( $klass, $method ) */ static public function allRegularTasks() { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $allJobs = $jobList->getAll(); $regularJobs = array(); foreach ($allJobs as $job) { @@ -118,7 +118,7 @@ class BackgroundJob { * @return associative array */ public static function findQueuedTask($id) { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); return $jobList->getById($id); } @@ -128,7 +128,7 @@ class BackgroundJob { * @return array with associative arrays */ public static function allQueuedTasks() { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $allJobs = $jobList->getAll(); $queuedJobs = array(); foreach ($allJobs as $job) { @@ -148,7 +148,7 @@ class BackgroundJob { * @return array with associative arrays */ public static function queuedTaskWhereAppIs($app) { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $allJobs = $jobList->getAll(); $queuedJobs = array(); foreach ($allJobs as $job) { @@ -186,7 +186,7 @@ class BackgroundJob { * Deletes a report */ public static function deleteQueuedTask($id) { - $jobList = new JobList(); + $jobList = \OC::$server->getJobList(); $job = $jobList->getById($id); if ($job) { $jobList->remove($job); diff --git a/lib/public/backgroundjob/ijob.php b/lib/public/backgroundjob/ijob.php new file mode 100644 index 00000000000..5231e9537a9 --- /dev/null +++ b/lib/public/backgroundjob/ijob.php @@ -0,0 +1,42 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP\BackgroundJob; + +interface IJob { + /** + * Run the background job with the registered argument + * + * @param \OCP\BackgroundJob\IJobList $jobList The job list that manages the state of this job + * @param \OC\Log $logger + */ + public function execute($jobList, $logger = null); + + /** + * Get the id of the background job + * This id is determined by the job list when a job is added to the list + * + * @return int + */ + public function getId(); + + /** + * Get the last time this job was run as unix timestamp + * + * @return int + */ + public function getLastRun(); + + /** + * Get the argument associated with the background job + * This is the argument that will be passed to the background job + * + * @return mixed + */ + public function getArgument(); +} diff --git a/lib/public/backgroundjob/ijoblist.php b/lib/public/backgroundjob/ijoblist.php new file mode 100644 index 00000000000..72f3fe863da --- /dev/null +++ b/lib/public/backgroundjob/ijoblist.php @@ -0,0 +1,77 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP\BackgroundJob; + +interface IJobList { + /** + * Add a job to the list + * + * @param \OCP\BackgroundJob\IJob |string $job + * @param mixed $argument The argument to be passed to $job->run() when the job is exectured + */ + public function add($job, $argument = null); + + /** + * Remove a job from the list + * + * @param \OCP\BackgroundJob\IJob|string $job + * @param mixed $argument + */ + public function remove($job, $argument = null); + + /** + * check if a job is in the list + * + * @param $job + * @param mixed $argument + * @return bool + */ + public function has($job, $argument); + + /** + * get all jobs in the list + * + * @return \OCP\BackgroundJob\IJob[] + */ + public function getAll(); + + /** + * get the next job in the list + * + * @return \OCP\BackgroundJob\IJob + */ + public function getNext(); + + /** + * @param int $id + * @return \OCP\BackgroundJob\IJob + */ + public function getById($id); + + /** + * set the job that was last ran to the current time + * + * @param \OCP\BackgroundJob\IJob $job + */ + public function setLastJob($job); + + /** + * get the id of the last ran job + * + * @return int + */ + public function getLastJob(); + + /** + * set the lastRun of $job to now + * + * @param \OCP\BackgroundJob\IJob $job + */ + public function setLastRun($job); +} diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index dcb00caf496..5fb51f9ecd5 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -183,4 +183,11 @@ interface IServerContainer { */ function getAvatarManager(); + /** + * Returns an job list for controlling background jobs + * + * @return \OCP\BackgroundJob\IJobList + */ + function getJobList(); + } |