]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make sure to catch php errors during job execution 19241/head
authorDaniel Kesselberg <mail@danielkesselberg.de>
Fri, 31 Jan 2020 15:04:04 +0000 (16:04 +0100)
committerDaniel Kesselberg <mail@danielkesselberg.de>
Fri, 31 Jan 2020 15:04:04 +0000 (16:04 +0100)
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
lib/private/BackgroundJob/Job.php
tests/lib/BackgroundJob/JobTest.php

index 8f11ebb4debe5c3a9c693e7bc1527a5e7e73834f..26c69a2486c56124eda26e14e0197a1deb45c9b2 100644 (file)
@@ -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',
index 6e5474e597ce58264f0f5ecc67cc0118791a75a9..b4048aa1c2257ee0c702ae5322e192279364ce98 100644 (file)
@@ -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;
        }