feat: add horizon server details to queue
This commit is contained in:
@@ -7,6 +7,7 @@ use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Horizon\Contracts\JobRepository;
|
||||
use Laravel\Horizon\Contracts\MetricsRepository;
|
||||
use Laravel\Horizon\Repositories\RedisJobRepository;
|
||||
|
||||
use function Laravel\Prompts\multiselect;
|
||||
use function Laravel\Prompts\select;
|
||||
@@ -14,7 +15,7 @@ use function Laravel\Prompts\table;
|
||||
|
||||
class HorizonManage extends Command
|
||||
{
|
||||
protected $signature = 'horizon:manage ';
|
||||
protected $signature = 'horizon:manage';
|
||||
|
||||
protected $description = 'Manage horizon';
|
||||
|
||||
@@ -28,6 +29,7 @@ class HorizonManage extends Command
|
||||
'workers' => 'Workers',
|
||||
'failed' => 'Failed Jobs',
|
||||
'failed-delete' => 'Failed Jobs - Delete',
|
||||
'purge-queues' => 'Purge Queues',
|
||||
]
|
||||
);
|
||||
|
||||
@@ -102,11 +104,11 @@ class HorizonManage extends Command
|
||||
|
||||
return;
|
||||
}
|
||||
dump($runningJobs);
|
||||
foreach ($runningJobs as $runningJob) {
|
||||
$runningJobsTable[] = [
|
||||
'id' => $runningJob->id,
|
||||
'name' => $runningJob->name,
|
||||
'reserved_at' => $runningJob->reserved_at ? now()->parse($runningJob->reserved_at)->format('Y-m-d H:i:s') : null,
|
||||
];
|
||||
}
|
||||
table($runningJobsTable);
|
||||
@@ -123,5 +125,15 @@ class HorizonManage extends Command
|
||||
}
|
||||
table($workersTable);
|
||||
}
|
||||
|
||||
if ($action === 'purge-queues') {
|
||||
$getQueues = app(CustomJobRepository::class)->getQueues();
|
||||
$queueName = select(
|
||||
label: 'Which queue to purge?',
|
||||
options: $getQueues,
|
||||
);
|
||||
$redisJobRepository = app(RedisJobRepository::class);
|
||||
$redisJobRepository->purge($queueName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,6 +237,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
|
||||
{
|
||||
$this->application_deployment_queue->update([
|
||||
'status' => ApplicationDeploymentStatus::IN_PROGRESS->value,
|
||||
'horizon_job_worker' => gethostname(),
|
||||
]);
|
||||
if ($this->server->isFunctional() === false) {
|
||||
$this->application_deployment_queue->addLogEntry('Server is not functional.');
|
||||
@@ -2389,10 +2390,12 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
|
||||
queue_next_deployment($this->application);
|
||||
// If the deployment is cancelled by the user, don't update the status
|
||||
if (
|
||||
$this->application_deployment_queue->status !== ApplicationDeploymentStatus::CANCELLED_BY_USER->value && $this->application_deployment_queue->status !== ApplicationDeploymentStatus::FAILED->value
|
||||
$this->application_deployment_queue->status !== ApplicationDeploymentStatus::CANCELLED_BY_USER->value &&
|
||||
$this->application_deployment_queue->status !== ApplicationDeploymentStatus::FAILED->value
|
||||
) {
|
||||
$this->application_deployment_queue->update([
|
||||
'status' => $status,
|
||||
'horizon_job_status' => $status,
|
||||
]);
|
||||
}
|
||||
if ($this->application_deployment_queue->status === ApplicationDeploymentStatus::FAILED->value) {
|
||||
|
||||
@@ -84,6 +84,7 @@ class DeploymentNavbar extends Component
|
||||
$this->application_deployment_queue->update([
|
||||
'current_process_id' => null,
|
||||
'status' => ApplicationDeploymentStatus::CANCELLED_BY_USER->value,
|
||||
'horizon_job_status' => ApplicationDeploymentStatus::CANCELLED_BY_USER->value,
|
||||
]);
|
||||
next_after_cancel($server);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Contracts\CustomJobRepositoryInterface;
|
||||
use App\Models\ApplicationDeploymentQueue;
|
||||
use App\Repositories\CustomJobRepository;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Laravel\Horizon\Contracts\JobRepository;
|
||||
use Laravel\Horizon\Events\JobReserved;
|
||||
|
||||
class HorizonServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -23,6 +26,22 @@ class HorizonServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
// Event::listen(function (JobReserved $event) {
|
||||
// $payload = $event->payload->decoded;
|
||||
// $jobName = $payload['displayName'];
|
||||
// if ($jobName === 'App\Jobs\ApplicationDeploymentJob') {
|
||||
// $tags = $payload['tags'];
|
||||
|
||||
// $deploymentQueueId = collect($tags)->first(function ($tag) {
|
||||
// return str_contains($tag, 'App\Models\ApplicationDeploymentQueue');
|
||||
// });
|
||||
// $deploymentQueueId = explode(':', $deploymentQueueId)[1];
|
||||
// $deploymentQueue = ApplicationDeploymentQueue::find($deploymentQueueId);
|
||||
// $deploymentQueue->update([
|
||||
// 'horizon_job_status' => 'reserved',
|
||||
// ]);
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,4 +68,14 @@ class CustomJobRepository extends RedisJobRepository implements CustomJobReposit
|
||||
|
||||
return $jobs;
|
||||
}
|
||||
|
||||
public function getQueues(): array
|
||||
{
|
||||
$queues = $this->connection()->keys('queue:*');
|
||||
$queues = array_map(function ($queue) {
|
||||
return explode(':', $queue)[2];
|
||||
}, $queues);
|
||||
|
||||
return $queues;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('application_deployment_queues', function (Blueprint $table) {
|
||||
$table->string('horizon_job_status')->nullable();
|
||||
$table->string('horizon_job_worker')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('application_deployment_queues', function (Blueprint $table) {
|
||||
$table->dropColumn('horizon_job_status');
|
||||
$table->dropColumn('horizon_job_worker');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user