getQuery(); $stuckTasks = $this->findStuckTasks(); $report = Report::createSuccess( sprintf( 'Rescheduling tasks for: age <= %s, tasks names IN %s', $query->getAgeDateTime()->format(DATE_ATOM), implode(',', $query->getWhitelist()) ) ); $restartService = $this->getRestartStuckTaskService(); $totalRestarted = 0; $totalErrors = 0; foreach ($stuckTasks as $stuckTask) { try { $restartService->restart($stuckTask); $successMessage = sprintf( 'Restarting: TaskLogId = %s, Label = %s, TaskName = %s', $stuckTask->getTaskLog()->getId(), $stuckTask->getTaskLog()->getLabel(), $stuckTask->getTaskLog()->getTaskName() ); $report->add(Report::createSuccess($successMessage)); $this->logInfo($successMessage); $totalRestarted++; } catch (Throwable $exception) { $totalErrors++; $errorMessage = sprintf( 'Error restarting: TaskLogId %s, Label %s, TaskName = %s, Error: %s', $stuckTask->getTaskLog()->getId(), $stuckTask->getTaskLog()->getLabel(), $stuckTask->getTaskLog()->getTaskName(), $exception->getMessage() ); $report->add(Report::createError($errorMessage)); $this->logError($errorMessage); } } $report->add( Report::createInfo( sprintf( 'Total: %s, Restarted: %s, Errors: %s', $stuckTasks->count(), $totalRestarted, $totalErrors ) ) ); return $report; } private function getRestartStuckTaskService(): RestartStuckTaskService { return $this->getServiceLocator()->get(RestartStuckTaskService::class); } }