Source of file CheckJobHealthTask.php
Size: 1,652 Bytes - Last Modified: 2021-12-23T10:33:37+00:00
/var/www/docs.ssmods.com/process/src/src/Tasks/CheckJobHealthTask.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 | <?php namespace Symbiote\QueuedJobs\Tasks; use Exception; use SilverStripe\Control\HTTPRequest; use SilverStripe\Dev\BuildTask; use Symbiote\QueuedJobs\Services\QueuedJob; use Symbiote\QueuedJobs\Services\QueuedJobService; class CheckJobHealthTask extends BuildTask { /** * {@inheritDoc} * @var string */ private static $segment = 'CheckJobHealthTask'; /** * {@inheritDoc} * @return string */ public function getDescription() { return _t( __CLASS__ . '.Description', 'A task used to check the health of jobs that are "running". Pass a specific queue as the "queue" ' . 'parameter or otherwise the "Queued" queue will be checked' ); } /** * Implement this method in the task subclass to * execute via the TaskRunner * * @param HTTPRequest $request * @return * * @throws Exception */ public function run($request) { $queue = $request->requestVar('queue') ?: QueuedJob::QUEUED; $jobHealth = $this->getService()->checkJobHealth($queue); $unhealthyJobCount = 0; foreach ($jobHealth as $type => $IDs) { $count = count($IDs); echo 'Detected and attempted restart on ' . $count . ' ' . $type . ' jobs'; $unhealthyJobCount = $unhealthyJobCount + $count; } if ($unhealthyJobCount > 0) { throw new Exception("$unhealthyJobCount jobs are unhealthy"); } echo 'All jobs are healthy'; } protected function getService() { return QueuedJobService::singleton(); } } |