summaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2023-04-20 15:29:47 +0200
committerMarcel Klehr <mklehr@gmx.net>2023-04-23 12:36:12 +0200
commit5608b5077873d1d6b83b2a0c7c45b6a6b243a61c (patch)
treeff24613f73f5fb0c6a947e60d52a0c563fdadaa5 /lib/public
parent94038e0673d38a0ddfcbda2d6ece8d0d145b0956 (diff)
downloadnextcloud-server-5608b5077873d1d6b83b2a0c7c45b6a6b243a61c.tar.gz
nextcloud-server-5608b5077873d1d6b83b2a0c7c45b6a6b243a61c.zip
Fix BackgroundJob tests
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/BackgroundJob/Job.php6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/public/BackgroundJob/Job.php b/lib/public/BackgroundJob/Job.php
index c1e129f1221..455fb3d42e7 100644
--- a/lib/public/BackgroundJob/Job.php
+++ b/lib/public/BackgroundJob/Job.php
@@ -44,6 +44,7 @@ abstract class Job implements IJob, IParallelAwareJob {
protected $argument;
protected ITimeFactory $time;
protected bool $allowParallelRuns = true;
+ private ?ILogger $logger = null;
/**
* @since 15.0.0
@@ -62,6 +63,7 @@ abstract class Job implements IJob, IParallelAwareJob {
* @since 15.0.0
*/
public function execute(IJobList $jobList, ILogger $logger = null) {
+ $this->logger = $logger;
$this->start($jobList);
}
@@ -71,7 +73,7 @@ abstract class Job implements IJob, IParallelAwareJob {
*/
public function start(IJobList $jobList): void {
$jobList->setLastRun($this);
- $logger = \OCP\Server::get(LoggerInterface::class);
+ $logger = $this->logger ?? \OCP\Server::get(LoggerInterface::class);
if (!$this->getAllowParallelRuns() && $jobList->hasReservedJob(get_class($this))) {
$logger->debug('Skipping ' . get_class($this) . ' job with ID ' . $this->getId() . ' because another job with the same class is already running', ['app' => 'cron']);
@@ -86,7 +88,7 @@ abstract class Job implements IJob, IParallelAwareJob {
$logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']);
$jobList->setExecutionTime($this, $timeTaken);
- } catch (\Exception $e) {
+ } catch (\Throwable $e) {
if ($logger) {
$logger->error('Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')', [
'app' => 'core',