[BUGFIX] Mark scheduler tasks as executed on PHP-level errors 04/59504/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Mon, 21 Jan 2019 10:36:51 +0000 (11:36 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 1 Feb 2019 17:20:45 +0000 (18:20 +0100)
The scheduler now catches any error implementing the `\Throwable`
interface thrown by a task to be able to mark such task as executed.

Resolves: #87502
Releases: master, 9.5, 8.7
Change-Id: I1f1bebee922c864ce8d7bfc3f0aa6e9434228e98
Reviewed-on: https://review.typo3.org/59504
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/scheduler/Classes/Scheduler.php
typo3/sysext/scheduler/Classes/Task/AbstractTask.php

index e36a0f6..93860d2 100644 (file)
@@ -149,8 +149,7 @@ class Scheduler implements SingletonInterface, LoggerAwareInterface
      *
      * @param Task\AbstractTask $task The task to execute
      * @return bool Whether the task was saved successfully to the database or not
-     * @throws FailedExecutionException
-     * @throws \Exception
+     * @throws \Throwable
      */
     public function executeTask(Task\AbstractTask $task)
     {
@@ -181,7 +180,7 @@ class Scheduler implements SingletonInterface, LoggerAwareInterface
                 if (!$successfullyExecuted) {
                     throw new FailedExecutionException('Task failed to execute successfully. Class: ' . get_class($task) . ', UID: ' . $task->getTaskUid(), 1250596541);
                 }
-            } catch (\Exception $e) {
+            } catch (\Throwable $e) {
                 // Store exception, so that it can be saved to database
                 $failure = $e;
             }
@@ -191,7 +190,7 @@ class Scheduler implements SingletonInterface, LoggerAwareInterface
             $this->logger->info('Task executed. Class: ' . get_class($task) . ', UID: ' . $task->getTaskUid());
             // Now that the result of the task execution has been handled,
             // throw the exception again, if any
-            if ($failure instanceof \Exception) {
+            if ($failure instanceof \Throwable) {
                 throw $failure;
             }
         }
index 312de7f..dc53729 100644 (file)
@@ -487,9 +487,9 @@ abstract class AbstractTask implements LoggerAwareInterface
      * Removes given execution from list
      *
      * @param int $executionID Id of the execution to remove.
-     * @param \Exception $failure An exception to signal a failed execution
+     * @param \Throwable $failure An exception to signal a failed execution
      */
-    public function unmarkExecution($executionID, \Exception $failure = null)
+    public function unmarkExecution($executionID, \Throwable $failure = null)
     {
         // Get the executions for the task
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
@@ -514,7 +514,7 @@ abstract class AbstractTask implements LoggerAwareInterface
             } else {
                 $runningExecutionsSerialized = '';
             }
-            if ($failure instanceof \Exception) {
+            if ($failure instanceof \Throwable) {
                 // Log failed execution
                 $logMessage = 'Task failed to execute successfully. Class: ' . static::class
                     . ', UID: ' . $this->taskUid . ', Code: ' . $failure->getCode() . ', ' . $failure->getMessage();