Submit
Path:
~
/
/
opt
/
psa
/
admin
/
plib
/
modules
/
wp-toolkit
/
vendor
/
plesk
/
background-tasks
/
src
/
Executor
/
ConsoleTasks
/
File Content:
SingleBackgroundTasksExecutor.php
<?php // Copyright 1999-2024. WebPros International GmbH. All rights reserved. namespace BackgroundTasks\Executor\ConsoleTasks; use BackgroundTasks\BaseTaskInterface; use BackgroundTasks\DatabaseStorage\BackgroundTaskBrokerInterface; use BackgroundTasks\Executor\ConsoleTasks\Queue\BackgroundTaskQueueInteface; use BackgroundTasks\Manager\TaskManagerInterface; use Psr\Log\LoggerInterface; /** * The presented class should be used to periodically kill hanged background tasks * with dead pid, it can't be used with multiple tasks executors. * * Class SingleBackgroundTasksExecutor * @package BackgroundTasks\Executor\ConsoleTasks */ class SingleBackgroundTasksExecutor extends \BackgroundTasks\Executor\ConsoleTasks\BackgroundTasksExecutor { private const KILL_ORPHANED_TASKS_PERIOD = 60; /** * @var TaskManagerInterface */ private $taskManager; public function __construct(TaskManagerInterface $taskManager, \BackgroundTasks\Executor\ConsoleTasks\BackgroundTaskProcessCreator $backgroundTaskProcessCreator, BackgroundTaskBrokerInterface $backgroundTaskBroker, BackgroundTaskQueueInteface $backgroundTaskQueue, LoggerInterface $logger, float $loopTimerInterval = 1.0, float $shutdownTimeout = 0, ?int $maxSimultaneouslyRunningTasks = null) { $this->taskManager = $taskManager; parent::__construct($backgroundTaskProcessCreator, $backgroundTaskBroker, $backgroundTaskQueue, $logger, $loopTimerInterval, $shutdownTimeout, $maxSimultaneouslyRunningTasks); } public function loop() : void { $loop = $this->getLoop(); $loop->addPeriodicTimer(self::KILL_ORPHANED_TASKS_PERIOD, function () { $this->killOrphanedTasks(); }); parent::loop(); } private function killOrphanedTasks() : void { $tasks = $this->backgroundTaskBroker->getAll(); foreach ($tasks as $task) { if (!$task->getPid() || !\in_array($task->getStatus(), [BaseTaskInterface::STATUS_RUNNING, BaseTaskInterface::STATUS_STARTED], \true)) { continue; } if (!\posix_getsid($task->getPid()) && ($taskDataStorage = $this->taskManager->getTaskDataStorage($task->getId(), $task->getCode()))) { $taskDataStorage->addError('Task is not responding'); $task->setStatus(BaseTaskInterface::STATUS_ERROR); } } } }
Submit
FILE
FOLDER
INFO
Name
Size
Permission
Action
Queue
---
0755
BackgroundTaskProcessCreator.php
3319 bytes
0644
BackgroundTasksExecutor.php
4362 bytes
0644
ChildProcessOutputLogger.php
1472 bytes
0644
SingleBackgroundTasksExecutor.php
2401 bytes
0644
N4ST4R_ID | Naxtarrr