diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2020-01-31 16:04:04 +0100 |
---|---|---|
committer | Backportbot <backportbot-noreply@rullzer.com> | 2020-02-03 08:55:22 +0000 |
commit | 5ce0b449603287e92986d621987d148f5b5a1b00 (patch) | |
tree | 2c5496980132d06ee846d078536c2fc6464f11ab | |
parent | 297debef34d1192548a1fc451c645e71b05e0a81 (diff) | |
download | nextcloud-server-5ce0b449603287e92986d621987d148f5b5a1b00.tar.gz nextcloud-server-5ce0b449603287e92986d621987d148f5b5a1b00.zip |
Make sure to catch php errors during job execution
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
-rw-r--r-- | lib/private/BackgroundJob/Job.php | 2 | ||||
-rw-r--r-- | tests/lib/BackgroundJob/JobTest.php | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/private/BackgroundJob/Job.php b/lib/private/BackgroundJob/Job.php index 8f11ebb4deb..26c69a2486c 100644 --- a/lib/private/BackgroundJob/Job.php +++ b/lib/private/BackgroundJob/Job.php @@ -63,7 +63,7 @@ abstract class Job implements IJob { $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->logException($e, [ 'app' => 'core', diff --git a/tests/lib/BackgroundJob/JobTest.php b/tests/lib/BackgroundJob/JobTest.php index 6e5474e597c..b4048aa1c22 100644 --- a/tests/lib/BackgroundJob/JobTest.php +++ b/tests/lib/BackgroundJob/JobTest.php @@ -39,6 +39,27 @@ class JobTest extends \Test\TestCase { $this->assertCount(1, $jobList->getAll()); } + public function testRemoveAfterError() { + $jobList = new DummyJobList(); + $job = new TestJob($this, function () { + $test = null; + $test->someMethod(); + }); + $jobList->add($job); + + $logger = $this->getMockBuilder(ILogger::class) + ->disableOriginalConstructor() + ->getMock(); + $logger->expects($this->once()) + ->method('logException') + ->with($this->isInstanceOf(\Throwable::class)); + + $this->assertCount(1, $jobList->getAll()); + $job->execute($jobList, $logger); + $this->assertTrue($this->run); + $this->assertCount(1, $jobList->getAll()); + } + public function markRun() { $this->run = true; } |