fix: delete resource if server is not functional

fix: set status to exited on all resources
This commit is contained in:
Andras Bacsai 2023-11-06 11:51:20 +01:00
parent b4a6499c83
commit 8b034f15fc
3 changed files with 21 additions and 3 deletions

View File

@ -2,7 +2,7 @@
namespace App\Http\Livewire\Project\Shared;
use App\Jobs\StopResourceJob;
use App\Jobs\DeleteResourceJob;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
@ -21,7 +21,7 @@ public function mount()
public function delete()
{
try {
StopResourceJob::dispatchSync($this->resource);
DeleteResourceJob::dispatchSync($this->resource);
return redirect()->route('project.resources', [
'project_uuid' => $this->parameters['project_uuid'],
'environment_name' => $this->parameters['environment_name']

View File

@ -60,6 +60,23 @@ public function handle(): void
$this->server->update([
'unreachable_count' => 0,
]);
// Update all applications, databases and services to exited
foreach($this->server->applications() as $application) {
$application->update(['status' => 'exited']);
}
foreach($this->server->databases() as $database) {
$database->update(['status' => 'exited']);
}
foreach($this->server->services() as $service) {
$apps = $service->applications()->get();
$dbs = $service->databases()->get();
foreach ($apps as $app) {
$app->update(['status' => 'exited']);
}
foreach ($dbs as $db) {
$db->update(['status' => 'exited']);
}
}
return;
}
$result = $this->server->validateConnection();

View File

@ -19,7 +19,7 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class StopResourceJob implements ShouldQueue, ShouldBeEncrypted
class DeleteResourceJob implements ShouldQueue, ShouldBeEncrypted
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@ -32,6 +32,7 @@ public function handle()
try {
$server = $this->resource->destination->server;
if (!$server->isFunctional()) {
$this->resource->delete();
return 'Server is not functional';
}
switch ($this->resource->type()) {