coolify/app/Actions/Application/IsHorizonQueueEmpty.php

38 lines
950 B
PHP
Raw Normal View History

<?php
namespace App\Actions\Application;
use Laravel\Horizon\Contracts\JobRepository;
use Lorisleiva\Actions\Concerns\AsAction;
2024-11-12 09:16:34 +00:00
class IsHorizonQueueEmpty
{
use AsAction;
public function handle()
{
$hostname = gethostname();
$recent = app(JobRepository::class)->getRecent();
if ($recent) {
$running = $recent->filter(function ($job) use ($hostname) {
$payload = json_decode($job->payload);
$tags = data_get($payload, 'tags');
return $job->status != 'completed' &&
$job->status != 'failed' &&
isset($tags) &&
is_array($tags) &&
in_array('server:'.$hostname, $tags);
});
if ($running->count() > 0) {
2024-11-12 09:16:34 +00:00
echo 'false';
2024-11-12 09:16:34 +00:00
return false;
}
}
2024-11-12 09:16:34 +00:00
echo 'true';
2024-11-12 09:16:34 +00:00
return true;
}
}