fix: service deletion

This commit is contained in:
Andras Bacsai 2024-01-31 09:58:41 +01:00
parent 1cef233db2
commit 0686e48e89
3 changed files with 8 additions and 17 deletions

View File

@ -13,7 +13,6 @@ class DeleteService
try { try {
$server = data_get($service, 'server'); $server = data_get($service, 'server');
if ($server->isFunctional()) { if ($server->isFunctional()) {
StopService::run($service);
$storagesToDelete = collect([]); $storagesToDelete = collect([]);
$service->environment_variables()->delete(); $service->environment_variables()->delete();
@ -46,7 +45,6 @@ class DeleteService
foreach ($service->databases()->get() as $database) { foreach ($service->databases()->get() as $database) {
$database->forceDelete(); $database->forceDelete();
} }
$service->forceDelete();
} }
} }
} }

View File

@ -10,6 +10,10 @@ class StopService
use AsAction; use AsAction;
public function handle(Service $service) public function handle(Service $service)
{ {
$server = $service->destination->server;
if (!$server->isFunctional()) {
return 'Server is not functional';
}
ray('Stopping service: ' . $service->name); ray('Stopping service: ' . $service->name);
$applications = $service->applications()->get(); $applications = $service->applications()->get();
foreach ($applications as $application) { foreach ($applications as $application) {

View File

@ -5,6 +5,7 @@ namespace App\Jobs;
use App\Actions\Application\StopApplication; use App\Actions\Application\StopApplication;
use App\Actions\Database\StopDatabase; use App\Actions\Database\StopDatabase;
use App\Actions\Service\DeleteService; use App\Actions\Service\DeleteService;
use App\Actions\Service\StopService;
use App\Models\Application; use App\Models\Application;
use App\Models\Service; use App\Models\Service;
use App\Models\StandaloneMariadb; use App\Models\StandaloneMariadb;
@ -30,33 +31,21 @@ class DeleteResourceJob implements ShouldQueue, ShouldBeEncrypted
public function handle() public function handle()
{ {
try { try {
$this->resource->forceDelete();
switch ($this->resource->type()) { switch ($this->resource->type()) {
case 'application': case 'application':
StopApplication::run($this->resource); StopApplication::run($this->resource);
$this->resource->forceDelete();
break; break;
case 'standalone-postgresql': case 'standalone-postgresql':
StopDatabase::run($this->resource);
$this->resource->forceDelete();
break;
case 'standalone-redis': case 'standalone-redis':
StopDatabase::run($this->resource);
$this->resource->forceDelete();
break;
case 'standalone-mongodb': case 'standalone-mongodb':
StopDatabase::run($this->resource);
$this->resource->forceDelete();
break;
case 'standalone-mysql': case 'standalone-mysql':
StopDatabase::run($this->resource);
$this->resource->forceDelete();
break;
case 'standalone-mariadb': case 'standalone-mariadb':
StopDatabase::run($this->resource); StopDatabase::run($this->resource);
$this->resource->forceDelete();
break; break;
case 'service': case 'service':
DeleteService::dispatch($this->resource); StopService::run($this->resource);
DeleteService::run($this->resource);
break; break;
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {