You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the title says. This is about a new operation for detecting a stuck scheduler task.
We recently had a customer where a scheduler task wouldn't stop running. This operation could help you detect such tasks.
I created the operation class myself to test it. @svewap , if you think this operation adds value to your extension, I would be happy to contribute to your project.
You can define the max runnign hours via parameter or use the default of 6 hours.
<?phpnamespaceWapplerSystems\ZabbixClient\Operation;
/** * This file is part of the "zabbix_client" Extension for TYPO3 CMS. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. */useDateTime;
useDoctrine\DBAL\DBALException;
useDoctrine\DBAL\Driver\Exception;
useTYPO3\CMS\Core\Database\Connection;
useTYPO3\CMS\Core\SingletonInterface;
useTYPO3\CMS\Core\Utility\GeneralUtility;
useTYPO3\CMS\Core\Database\ConnectionPool;
useWapplerSystems\ZabbixClient\OperationResult;
class HasStuckSchedulerTask implements IOperation, SingletonInterface
{
constMAX_RUNNING_HOURS = 6;
/** * @param array $parameter * @return OperationResult * * @throws Exception|DBALException */publicfunctionexecute($parameter = [])
{
$maxRunningHours = intval(isset($parameter['maxRunningHours']) ? $parameter['maxRunningHours'] : 0);
// Make sure we do not use a number smaller than 1 here.if($maxRunningHours < 1) {
$maxRunningHours = self::MAX_RUNNING_HOURS;
}
$schedulerRecords = $this->fetchSchedulerTasks();
if (0 === count($schedulerRecords)) {
// No tasks found.returnnewOperationResult(true, false);
}
foreach ($schedulerRecordsas$schedulerRecord) {
// Check if the task is running.$isRunning = !empty($schedulerRecord['serialized_executions']);
if (!$isRunning) {
continue;
}
// Validate for required column value (lastexecution_time).if (empty($schedulerRecord['lastexecution_time'])) {
continue;
}
// Compare lastexecution_time with current time.$currentDateTime = newDateTime();
$lastExecutedDateTime = (newDateTime())->setTimestamp((int)$schedulerRecord['lastexecution_time']);
$runningHours = intval($currentDateTime->diff($lastExecutedDateTime)->format('%h'));
$runningHours += intval($currentDateTime->diff($lastExecutedDateTime)->days) * 24;
if ($runningHours >= $maxRunningHours) {
returnnewOperationResult(true, true);
}
}
// No task is running.returnnewOperationResult(true, false);
}
/** * @return array * * @throws Exception|DBALException */privatefunctionfetchSchedulerTasks()
{
/** @var ConnectionPool $connectionPool */$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable('tx_scheduler_task');
$queryBuilder
->select('uid', 'serialized_executions', 'lastexecution_time')
->from('tx_scheduler_task')
->where(
$queryBuilder->expr()->eq('disable', $queryBuilder->createNamedParameter(0, Connection::PARAM_INT))
);
if (version_compare(TYPO3_version, '9.0.0', '>=')) {
$queryBuilder->andWhere(
$queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, Connection::PARAM_INT))
);
}
return$queryBuilder->execute()->fetchAllAssociative();
}
}
The text was updated successfully, but these errors were encountered:
The task will be included in the next release for TYPO3 12. If an older TYPO3 version is needed feel free to reopen it. My personal focus is set on 12 and 13.
As the title says. This is about a new operation for detecting a stuck scheduler task.
We recently had a customer where a scheduler task wouldn't stop running. This operation could help you detect such tasks.
I created the operation class myself to test it. @svewap , if you think this operation adds value to your extension, I would be happy to contribute to your project.
The text was updated successfully, but these errors were encountered: