stop status event

This commit is contained in:
Andras Bacsai 2023-12-08 13:07:42 +01:00
parent 4071e096bc
commit 205995cabe
3 changed files with 12 additions and 8 deletions

View File

@ -17,8 +17,6 @@ class RunRemoteProcess
public bool $hide_from_output; public bool $hide_from_output;
public bool $is_finished;
public bool $ignore_errors; public bool $ignore_errors;
public $call_event_on_finish = null; public $call_event_on_finish = null;
@ -36,7 +34,7 @@ class RunRemoteProcess
/** /**
* Create a new job instance. * Create a new job instance.
*/ */
public function __construct(Activity $activity, bool $hide_from_output = false, bool $is_finished = false, bool $ignore_errors = false, $call_event_on_finish = null) public function __construct(Activity $activity, bool $hide_from_output = false, bool $ignore_errors = false, $call_event_on_finish = null)
{ {
if ($activity->getExtraProperty('type') !== ActivityTypes::INLINE->value) { if ($activity->getExtraProperty('type') !== ActivityTypes::INLINE->value) {
@ -45,7 +43,6 @@ class RunRemoteProcess
$this->activity = $activity; $this->activity = $activity;
$this->hide_from_output = $hide_from_output; $this->hide_from_output = $hide_from_output;
$this->is_finished = $is_finished;
$this->ignore_errors = $ignore_errors; $this->ignore_errors = $ignore_errors;
$this->call_event_on_finish = $call_event_on_finish; $this->call_event_on_finish = $call_event_on_finish;
} }
@ -82,7 +79,7 @@ class RunRemoteProcess
if ($this->activity->properties->get('status') === ProcessStatus::ERROR->value) { if ($this->activity->properties->get('status') === ProcessStatus::ERROR->value) {
$status = ProcessStatus::ERROR; $status = ProcessStatus::ERROR;
} else { } else {
if ($processResult->exitCode() == 0 && $this->is_finished) { if ($processResult->exitCode() == 0) {
$status = ProcessStatus::FINISHED; $status = ProcessStatus::FINISHED;
} }
if ($processResult->exitCode() != 0 && !$this->ignore_errors) { if ($processResult->exitCode() != 0 && !$this->ignore_errors) {
@ -110,7 +107,6 @@ class RunRemoteProcess
try { try {
event(resolve("App\\Events\\$this->call_event_on_finish", [ event(resolve("App\\Events\\$this->call_event_on_finish", [
'userId' => $this->activity->causer_id, 'userId' => $this->activity->causer_id,
'typeUuid' => $this->activity->getExtraProperty('type_uuid'),
])); ]));
} catch (\Throwable $e) { } catch (\Throwable $e) {
ray($e); ray($e);

View File

@ -16,6 +16,12 @@ class ServiceStatusChanged implements ShouldBroadcast
public $userId; public $userId;
public function __construct($userId = null) public function __construct($userId = null)
{ {
if (is_null($userId)) {
$userId = auth()->user()->id ?? null;
}
if (is_null($userId)) {
throw new \Exception("User id is null");
}
$this->userId = $userId; $this->userId = $userId;
} }

View File

@ -4,6 +4,7 @@ namespace App\Livewire\Project\Service;
use App\Actions\Service\StartService; use App\Actions\Service\StartService;
use App\Actions\Service\StopService; use App\Actions\Service\StopService;
use App\Events\ServiceStatusChanged;
use App\Jobs\ContainerStatusJob; use App\Jobs\ContainerStatusJob;
use App\Models\Service; use App\Models\Service;
use Livewire\Component; use Livewire\Component;
@ -16,7 +17,8 @@ class Navbar extends Component
public array $query; public array $query;
public $isDeploymentProgress = false; public $isDeploymentProgress = false;
public function checkDeployments() { public function checkDeployments()
{
$activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first(); $activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first();
$status = data_get($activity, 'properties.status'); $status = data_get($activity, 'properties.status');
if ($status === 'queued' || $status === 'in_progress') { if ($status === 'queued' || $status === 'in_progress') {
@ -64,6 +66,6 @@ class Navbar extends Component
} else { } else {
$this->dispatch('success', 'Service stopped successfully.'); $this->dispatch('success', 'Service stopped successfully.');
} }
$this->dispatch('checkStatus'); event(new ServiceStatusChanged(userId: auth()->user()->id));
} }
} }