Deprecated ILogger from IJob

Since the ILogger will be soon removed we need to ensure that nothing in
the public api use it.

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
pull/33047/head
Carl Schwan 4 years ago
parent 9475cc02b2
commit 19a2d6f6e7
No known key found for this signature in database
GPG Key ID: C3AA6B3A5EFA7AC5
  1. 21
      lib/public/BackgroundJob/IJob.php
  2. 30
      lib/public/BackgroundJob/Job.php
  3. 15
      lib/public/BackgroundJob/QueuedJob.php
  4. 20
      lib/public/BackgroundJob/TimedJob.php

@ -29,7 +29,10 @@ namespace OCP\BackgroundJob;
use OCP\ILogger;
/**
* Interface IJob
* This interface represend a backgroud job run with cron
*
* To implement a background job, you must extend either \OCP\BackgroundJob\Job,
* \OCP\BackgroundJob\TimedJob or \OCP\BackgroundJob\QueuedJob
*
* @since 7.0.0
*/
@ -49,9 +52,25 @@ interface IJob {
* @param IJobList $jobList The job list that manages the state of this job
* @param ILogger|null $logger
* @since 7.0.0
* @deprecated since 25.0.0 Use start() instead. This method will be removed
* with the ILogger interface
*/
public function execute(IJobList $jobList, ILogger $logger = null);
/**
* Start the background job with the registered argument
*
* This methods will take care of running the background job, of initializing
* the state and cleaning up the job list after running the job.
*
* For common background job scenario, you will want to use TimedJob or QueuedJob
* instead of overwritting this method.
*
* @param IJobList $jobList The job list that manages the state of this job
* @since 25.0.0
*/
public function start(IJobList $jobList): void;
/**
* @since 7.0.0
*/

@ -38,18 +38,10 @@ use OCP\ILogger;
* @since 15.0.0
*/
abstract class Job implements IJob {
/** @var int $id */
protected $id;
/** @var int $lastRun */
protected $lastRun;
/** @var mixed $argument */
protected int $id = 0;
protected int $lastRun = 0;
protected $argument;
/** @var ITimeFactory */
protected $time;
protected ITimeFactory $time;
/**
* @since 15.0.0
@ -68,10 +60,16 @@ abstract class Job implements IJob {
* @since 15.0.0
*/
public function execute(IJobList $jobList, ILogger $logger = null) {
$this->start($jobList);
}
/**
* @inheritdoc
* @since 25.0.0
*/
public function start(IJobList $jobList): void {
$jobList->setLastRun($this);
if ($logger === null) {
$logger = \OC::$server->getLogger();
}
$logger = \OCP\Server::get(LoggerInterface::class);
try {
$jobStartTime = $this->time->getTime();
@ -83,9 +81,9 @@ abstract class Job implements IJob {
$jobList->setExecutionTime($this, $timeTaken);
} catch (\Exception $e) {
if ($logger) {
$logger->logException($e, [
$logger->error('Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')', [
'app' => 'core',
'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')'
'exception' => $e,
]);
}
}

@ -35,15 +35,26 @@ use OCP\ILogger;
abstract class QueuedJob extends Job {
/**
* run the job, then remove it from the joblist
* Run the job, then remove it from the joblist
*
* @param IJobList $jobList
* @param ILogger|null $logger
*
* @since 15.0.0
* @deprecated since 25.0.0 Use start() instead. This method will be removed
* with the ILogger interface
*/
final public function execute($jobList, ILogger $logger = null) {
$this->start($jobList);
}
/**
* Run the job, then remove it from the joblist
*
* @since 15.0.0
*/
final public function start(IJobList $jobList): void {
$jobList->remove($this, $this->argument);
parent::execute($jobList, $logger);
parent::start($jobList);
}
}

@ -36,13 +36,11 @@ use OCP\ILogger;
* @since 15.0.0
*/
abstract class TimedJob extends Job {
/** @var int */
protected $interval = 0;
/** @var int */
protected $timeSensitivity = IJob::TIME_SENSITIVE;
protected int $interval = 0;
protected int $timeSensitivity = IJob::TIME_SENSITIVE;
/**
* set the interval for the job
* Set the interval for the job
*
* @param int $seconds the time to pass between two runs of the same job in seconds
*
@ -89,10 +87,20 @@ abstract class TimedJob extends Job {
* @param ILogger|null $logger
*
* @since 15.0.0
* @deprecated since 25.0.0 Use start() instead
*/
final public function execute($jobList, ILogger $logger = null) {
$this->start($jobList);
}
/**
* Run the job if the last run is is more than the interval ago
*
* @since 25.0.0
*/
final public function start(IJobList $jobList): void {
if (($this->time->getTime() - $this->lastRun) > $this->interval) {
parent::execute($jobList, $logger);
parent::start($jobList);
}
}
}

Loading…
Cancel
Save