2023-09-22 09:23:49 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Project\Service;
|
2023-09-22 09:23:49 +00:00
|
|
|
|
2023-12-14 13:50:38 +00:00
|
|
|
use App\Actions\Shared\PullImage;
|
2023-09-22 09:23:49 +00:00
|
|
|
use App\Actions\Service\StartService;
|
|
|
|
use App\Actions\Service\StopService;
|
2023-12-08 12:07:42 +00:00
|
|
|
use App\Events\ServiceStatusChanged;
|
2023-12-08 11:12:44 +00:00
|
|
|
use App\Jobs\ContainerStatusJob;
|
2023-09-22 09:23:49 +00:00
|
|
|
use App\Models\Service;
|
|
|
|
use Livewire\Component;
|
2023-12-08 11:12:44 +00:00
|
|
|
use Spatie\Activitylog\Models\Activity;
|
2023-09-22 09:23:49 +00:00
|
|
|
|
|
|
|
class Navbar extends Component
|
|
|
|
{
|
|
|
|
public Service $service;
|
|
|
|
public array $parameters;
|
|
|
|
public array $query;
|
2023-12-08 11:12:44 +00:00
|
|
|
public $isDeploymentProgress = false;
|
2023-09-22 09:23:49 +00:00
|
|
|
|
2023-12-08 12:07:42 +00:00
|
|
|
public function checkDeployments()
|
|
|
|
{
|
2023-12-08 11:12:44 +00:00
|
|
|
$activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first();
|
|
|
|
$status = data_get($activity, 'properties.status');
|
|
|
|
if ($status === 'queued' || $status === 'in_progress') {
|
|
|
|
$this->isDeploymentProgress = true;
|
|
|
|
} else {
|
|
|
|
$this->isDeploymentProgress = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function getListeners()
|
|
|
|
{
|
|
|
|
return [
|
2023-12-08 12:55:55 +00:00
|
|
|
"serviceStatusChanged"
|
2023-12-08 11:12:44 +00:00
|
|
|
];
|
|
|
|
}
|
2023-12-08 11:48:21 +00:00
|
|
|
public function serviceStatusChanged()
|
|
|
|
{
|
|
|
|
$this->service->refresh();
|
|
|
|
}
|
2023-09-22 09:23:49 +00:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.project.service.navbar');
|
|
|
|
}
|
2023-12-11 12:43:16 +00:00
|
|
|
public function check_status($showNotification = false)
|
2023-12-08 11:12:44 +00:00
|
|
|
{
|
2023-12-11 12:43:16 +00:00
|
|
|
dispatch_sync(new ContainerStatusJob($this->service->destination->server));
|
2023-11-05 08:49:23 +00:00
|
|
|
$this->service->refresh();
|
2023-12-11 12:43:16 +00:00
|
|
|
if ($showNotification) $this->dispatch('success', 'Service status updated.');
|
2023-11-05 08:49:23 +00:00
|
|
|
}
|
2023-09-22 09:23:49 +00:00
|
|
|
public function deploy()
|
|
|
|
{
|
2023-12-08 11:12:44 +00:00
|
|
|
$this->checkDeployments();
|
|
|
|
if ($this->isDeploymentProgress) {
|
|
|
|
$this->dispatch('error', 'There is a deployment in progress.');
|
|
|
|
return;
|
|
|
|
}
|
2023-09-22 09:23:49 +00:00
|
|
|
$this->service->parse();
|
|
|
|
$activity = StartService::run($this->service);
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('newMonitorActivity', $activity->id);
|
2023-09-22 09:23:49 +00:00
|
|
|
}
|
2023-11-07 09:18:28 +00:00
|
|
|
public function stop(bool $forceCleanup = false)
|
2023-09-22 09:23:49 +00:00
|
|
|
{
|
|
|
|
StopService::run($this->service);
|
|
|
|
$this->service->refresh();
|
2023-11-07 09:18:28 +00:00
|
|
|
if ($forceCleanup) {
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('success', 'Force cleanup service successfully.');
|
2023-11-07 09:18:28 +00:00
|
|
|
} else {
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('success', 'Service stopped successfully.');
|
2023-11-07 09:18:28 +00:00
|
|
|
}
|
2023-12-08 17:32:08 +00:00
|
|
|
ServiceStatusChanged::dispatch();
|
2023-09-22 09:23:49 +00:00
|
|
|
}
|
2023-12-14 13:50:38 +00:00
|
|
|
public function restart()
|
|
|
|
{
|
|
|
|
$this->checkDeployments();
|
|
|
|
if ($this->isDeploymentProgress) {
|
|
|
|
$this->dispatch('error', 'There is a deployment in progress.');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PullImage::run($this->service);
|
|
|
|
$this->dispatch('image-pulled');
|
|
|
|
StopService::run($this->service);
|
|
|
|
$this->service->parse();
|
|
|
|
$activity = StartService::run($this->service);
|
|
|
|
$this->dispatch('newMonitorActivity', $activity->id);
|
|
|
|
}
|
2023-09-22 09:23:49 +00:00
|
|
|
}
|