lasthourcloud/app/Http/Livewire/Project/Application/DeploymentNavbar.php

45 lines
1.5 KiB
PHP
Raw Normal View History

2023-05-30 13:52:17 +00:00
<?php
namespace App\Http\Livewire\Project\Application;
use App\Enums\ProcessStatus;
use App\Models\Application;
use App\Models\ApplicationDeploymentQueue;
use Livewire\Component;
2023-05-31 10:38:36 +00:00
class DeploymentNavbar extends Component
2023-05-30 13:52:17 +00:00
{
public Application $application;
public $activity;
public string $deployment_uuid;
2023-05-31 12:42:37 +00:00
protected $listeners = ['deploymentFinished'];
public function deploymentFinished()
{
$this->activity->refresh();
}
2023-05-30 13:52:17 +00:00
public function cancel()
{
try {
2023-05-31 10:38:36 +00:00
ray('Cancelling deployment: ' . $this->deployment_uuid . ' of application: ' . $this->application->uuid);
// Update deployment queue
$deployment = ApplicationDeploymentQueue::where('deployment_uuid', $this->deployment_uuid)->first();
$deployment->status = 'cancelled by user';
2023-05-30 13:52:17 +00:00
$deployment->save();
2023-05-31 10:38:36 +00:00
// Update activity
2023-05-30 13:52:17 +00:00
$this->activity->properties = $this->activity->properties->merge([
'exitCode' => 1,
'status' => ProcessStatus::CANCELLED->value,
]);
$this->activity->save();
2023-05-31 10:38:36 +00:00
// Remove builder container
instant_remote_process(["docker rm -f {$this->deployment_uuid}"], $this->application->destination->server, throwError: false, repeat: 25);
queue_next_deployment($this->application);
2023-06-09 13:55:21 +00:00
} catch (\Throwable $e) {
return general_error_handler(err: $e, that: $this);
2023-05-30 13:52:17 +00:00
}
}
}