mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 08:42:38 -04:00
Status checks now queue a delayed check for each application, preview, service part, or database that goes from up to exited. After 2 minutes it sends the "Resource status changes" notification if the resource is still stopped, no deployment runs, and Coolify did not stop it. Each resource sends at most one notification in 15 minutes. Closes #9493
38 lines
1.3 KiB
PHP
38 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Application;
|
|
|
|
use App\Events\ServiceStatusChanged;
|
|
use App\Jobs\NotifyResourceStoppedJob;
|
|
use App\Models\ApplicationPreview;
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
class StopApplicationPreview
|
|
{
|
|
use AsAction;
|
|
|
|
public function handle(ApplicationPreview $preview, bool $resetRestartCount = true, bool $removeContainer = true): void
|
|
{
|
|
$application = $preview->application;
|
|
$server = $application->destination->server;
|
|
NotifyResourceStoppedJob::expectStop($preview, $application->settings->stopGracePeriodSeconds());
|
|
$containers = getCurrentApplicationContainerStatus($server, $application, $preview->pull_request_id);
|
|
|
|
foreach ($containers->pluck('Names') as $containerName) {
|
|
$escapedContainerName = escapeshellarg($containerName);
|
|
$commands = [dockerStopCommand($application->settings->stopGracePeriodSeconds(), $escapedContainerName, $server)];
|
|
if ($removeContainer) {
|
|
$commands[] = "docker rm -f {$escapedContainerName}";
|
|
}
|
|
instant_remote_process($commands, $server, false);
|
|
}
|
|
|
|
$preview->update(['status' => 'exited']);
|
|
if ($resetRestartCount) {
|
|
$preview->resetRestartLimit();
|
|
}
|
|
|
|
ServiceStatusChanged::dispatch($application->environment->project->team->id);
|
|
}
|
|
}
|