17 use Psr\Log\LoggerAwareInterface;
18 use Psr\Log\LoggerAwareTrait;
100 $this->scheduler = GeneralUtility::makeInstance(\
TYPO3\CMS\
Scheduler\Scheduler::class);
101 $this->execution = GeneralUtility::makeInstance(Execution::class);
113 abstract public function execute();
135 $this->taskUid = (int)$id;
155 return $GLOBALS[
'LANG']->sL(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'scheduler'][
'tasks'][static::class][
'title']);
165 return $GLOBALS[
'LANG']->sL(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'scheduler'][
'tasks'][static::class][
'description']);
175 return static::class;
196 $this->disabled =
true;
198 $this->disabled =
false;
209 $this->runOnNextCronJob = $flag;
229 $this->executionTime = (int)$timestamp;
288 $this->scheduler = GeneralUtility::makeInstance(\
TYPO3\CMS\
Scheduler\Scheduler::class);
289 $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
300 $this->scheduler =
null;
301 $this->logger =
null;
312 $execution = GeneralUtility::makeInstance(Execution::class);
335 $execution = GeneralUtility::makeInstance(Execution::class);
340 if (empty($cron_cmd)) {
381 return $this->execution->getNextExecution();
391 return $this->execution->getMultiple();
402 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
403 ->getQueryBuilderForTable(
'tx_scheduler_task');
405 ->select(
'serialized_executions')
406 ->from(
'tx_scheduler_task')
408 $queryBuilder->expr()->eq(
'uid', $queryBuilder->createNamedParameter($this->taskUid, \PDO::PARAM_INT))
413 if ($row && !empty($row[
'serialized_executions'])) {
427 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
428 ->getQueryBuilderForTable(
'tx_scheduler_task');
431 ->select(
'serialized_executions')
432 ->from(
'tx_scheduler_task')
434 $queryBuilder->expr()->eq(
'uid', $queryBuilder->createNamedParameter($this->taskUid, \PDO::PARAM_INT))
439 $runningExecutions = [];
440 if ($row && !empty($row[
'serialized_executions'])) {
441 $runningExecutions = unserialize($row[
'serialized_executions']);
445 $numExecutions = count($runningExecutions);
446 $runningExecutions[$numExecutions] = time();
447 GeneralUtility::makeInstance(ConnectionPool::class)
448 ->getConnectionForTable(
'tx_scheduler_task')
452 'serialized_executions' => serialize($runningExecutions),
453 'lastexecution_time' => time(),
458 'uid' => $this->taskUid
464 return $numExecutions;
476 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
477 ->getQueryBuilderForTable(
'tx_scheduler_task');
480 ->select(
'serialized_executions')
481 ->from(
'tx_scheduler_task')
483 $queryBuilder->expr()->eq(
'uid', $queryBuilder->createNamedParameter($this->taskUid, \PDO::PARAM_INT))
488 if ($row && $row[
'serialized_executions'] !==
'') {
489 $runningExecutions = unserialize($row[
'serialized_executions']);
491 unset($runningExecutions[$executionID]);
492 if (!empty($runningExecutions)) {
494 $runningExecutionsSerialized = serialize($runningExecutions);
496 $runningExecutionsSerialized =
'';
498 if ($failure instanceof \Throwable) {
500 $logMessage =
'Task failed to execute successfully. Class: ' . static::class
501 .
', UID: ' . $this->taskUid .
', Code: ' . $failure->getCode() .
', ' . $failure->getMessage();
502 $this->logger->error($logMessage, [
'exception' => $failure]);
504 $failureString = serialize([
505 'code' => $failure->getCode(),
506 'message' => $failure->getMessage(),
507 'file' => $failure->getFile(),
508 'line' => $failure->getLine(),
509 'traceString' => $failure->getTraceAsString(),
515 GeneralUtility::makeInstance(ConnectionPool::class)
516 ->getConnectionForTable(
'tx_scheduler_task')
520 'serialized_executions' => $runningExecutionsSerialized,
521 'lastexecution_failure' => $failureString
524 'uid' => $this->taskUid
541 $result = GeneralUtility::makeInstance(ConnectionPool::class)
542 ->getConnectionForTable(
'tx_scheduler_task')
546 'serialized_executions' =>
''
549 'uid' => $this->taskUid
555 return (
bool)$result;
563 public function save()
565 return $this->scheduler->saveTask($this);
574 $this->execution = GeneralUtility::makeInstance(Execution::class);
580 public function remove()
582 $this->scheduler->removeTask($this);
604 $this->logger->error(
'A Task Exception was captured: ' . $e->getMessage() .
' (' . $e->getCode() .
')', [
'exception' => $e]);