Skip to content

Commit 04e504b

Browse files
committed
chore: Refactor DockerCleanupJob to remove unused middleware and uniqueId method
1 parent 960f970 commit 04e504b

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

app/Actions/Application/StopApplication.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace App\Actions\Application;
44

5-
use App\Models\Application;
65
use App\Actions\Server\CleanupDocker;
6+
use App\Models\Application;
77
use Lorisleiva\Actions\Concerns\AsAction;
88

99
class StopApplication
@@ -14,13 +14,14 @@ public function handle(Application $application, bool $previewDeployments = fals
1414
{
1515
try {
1616
$server = $application->destination->server;
17-
if (!$server->isFunctional()) {
17+
if (! $server->isFunctional()) {
1818
return 'Server is not functional';
1919
}
20-
ray('Stopping application: ' . $application->name);
20+
ray('Stopping application: '.$application->name);
2121

2222
if ($server->isSwarm()) {
2323
instant_remote_process(["docker stack rm {$application->uuid}"], $server);
24+
2425
return;
2526
}
2627

@@ -32,10 +33,11 @@ public function handle(Application $application, bool $previewDeployments = fals
3233
}
3334

3435
if ($dockerCleanup) {
35-
CleanupDocker::run($server, true);
36+
CleanupDocker::dispatch($server, true);
3637
}
3738
} catch (\Exception $e) {
3839
ray($e->getMessage());
40+
3941
return $e->getMessage();
4042
}
4143
}

app/Actions/Database/StopDatabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|St
2828
$this->stopContainer($database, $database->uuid, 300);
2929
if (! $isDeleteOperation) {
3030
if ($dockerCleanup) {
31-
CleanupDocker::run($server, true);
31+
CleanupDocker::dispatch($server, true);
3232
}
3333
}
3434

app/Actions/Service/DeleteService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace App\Actions\Service;
44

5-
use App\Models\Service;
65
use App\Actions\Server\CleanupDocker;
6+
use App\Models\Service;
77
use Lorisleiva\Actions\Concerns\AsAction;
88

99
class DeleteService
@@ -36,7 +36,7 @@ public function handle(Service $service, bool $deleteConfigurations, bool $delet
3636
}
3737

3838
// Execute volume deletion first, this must be done first otherwise volumes will not be deleted.
39-
if (!empty($commands)) {
39+
if (! empty($commands)) {
4040
foreach ($commands as $command) {
4141
$result = instant_remote_process([$command], $server, false);
4242
if ($result !== 0) {
@@ -70,7 +70,7 @@ public function handle(Service $service, bool $deleteConfigurations, bool $delet
7070
$service->forceDelete();
7171

7272
if ($dockerCleanup) {
73-
CleanupDocker::run($server, true);
73+
CleanupDocker::dispatch($server, true);
7474
}
7575
}
7676
}

app/Actions/Service/StopService.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace App\Actions\Service;
44

5-
use App\Models\Service;
65
use App\Actions\Server\CleanupDocker;
6+
use App\Models\Service;
77
use Lorisleiva\Actions\Concerns\AsAction;
88

99
class StopService
@@ -14,21 +14,22 @@ public function handle(Service $service, bool $isDeleteOperation = false, bool $
1414
{
1515
try {
1616
$server = $service->destination->server;
17-
if (!$server->isFunctional()) {
17+
if (! $server->isFunctional()) {
1818
return 'Server is not functional';
1919
}
2020

2121
$containersToStop = $service->getContainersToStop();
2222
$service->stopContainers($containersToStop, $server);
2323

24-
if (!$isDeleteOperation) {
24+
if (! $isDeleteOperation) {
2525
$service->delete_connected_networks($service->uuid);
2626
if ($dockerCleanup) {
27-
CleanupDocker::run($server, true);
27+
CleanupDocker::dispatch($server, true);
2828
}
2929
}
3030
} catch (\Exception $e) {
3131
ray($e->getMessage());
32+
3233
return $e->getMessage();
3334
}
3435
}

app/Jobs/DeleteResourceJob.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function handle()
8080
|| $this->resource instanceof StandaloneClickhouse;
8181
$server = data_get($this->resource, 'server') ?? data_get($this->resource, 'destination.server');
8282
if (($this->dockerCleanup || $isDatabase) && $server) {
83-
CleanupDocker::run($server, true);
83+
CleanupDocker::dispatch($server, true);
8484
}
8585

8686
if ($this->deleteConnectedNetworks && ! $isDatabase) {
@@ -92,7 +92,7 @@ public function handle()
9292
} finally {
9393
$this->resource->forceDelete();
9494
if ($this->dockerCleanup) {
95-
CleanupDocker::run($server, true);
95+
CleanupDocker::dispatch($server, true);
9696
}
9797
Artisan::queue('cleanup:stucked-resources');
9898
}

0 commit comments

Comments
 (0)