option('seconds'); $deployments = ApplicationDeploymentQueue::query()->whereIn('status', [ ApplicationDeploymentStatus::IN_PROGRESS, ApplicationDeploymentStatus::QUEUED, ])->where('created_at', '<=', now()->subSeconds($seconds))->get(); if ($deployments->isEmpty()) { $this->info('No deployments found in the last '.$seconds.' seconds.'); return; } $this->info('Found '.$deployments->count().' deployments created in the last '.$seconds.' seconds.'); foreach ($deployments as $deployment) { if ($this->option('force')) { $this->info('Deployment '.$deployment->id.' created at '.$deployment->created_at.' is older than '.$seconds.' seconds. Setting status to failed.'); $this->cancelDeployment($deployment); } else { $this->info('Deployment '.$deployment->id.' created at '.$deployment->created_at.' is older than '.$seconds.' seconds. Setting status to failed.'); if ($this->confirm('Do you want to cancel this deployment?', true)) { $this->cancelDeployment($deployment); } } } } private function cancelDeployment(ApplicationDeploymentQueue $applicationDeploymentQueue) { $applicationDeploymentQueue->update(['status' => ApplicationDeploymentStatus::FAILED]); if ($applicationDeploymentQueue->server?->isFunctional()) { remote_process(['docker rm -f '.$applicationDeploymentQueue->deployment_uuid], $applicationDeploymentQueue->server, false); } } }