Skip to content

Commit

Permalink
Avoid rollback if node is unreachable
Browse files Browse the repository at this point in the history
  • Loading branch information
RMartinOscar committed Jan 6, 2025
1 parent b5bcdc7 commit c90d336
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 10 additions & 2 deletions app/Filament/Admin/Resources/ServerResource/Pages/EditServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,11 @@ public function form(Form $form): Form
->color('warning')
->hidden(fn (Server $server) => $server->isSuspended())
->action(function (SuspensionService $suspensionService, Server $server) {
$suspensionService->handle($server, SuspensionService::ACTION_SUSPEND);
try {
$suspensionService->handle($server, SuspensionService::ACTION_SUSPEND);
} catch (\Exception $exception) {
Notification::make()->warning()->title('Server Suspension')->body($exception->getMessage())->send();
}
Notification::make()->success()->title('Server Suspended!')->send();

$this->refreshFormData(['status', 'docker']);
Expand All @@ -802,7 +806,11 @@ public function form(Form $form): Form
->color('success')
->hidden(fn (Server $server) => !$server->isSuspended())
->action(function (SuspensionService $suspensionService, Server $server) {
$suspensionService->handle($server, SuspensionService::ACTION_UNSUSPEND);
try {
$suspensionService->handle($server, SuspensionService::ACTION_UNSUSPEND);
} catch (\Exception $exception) {
Notification::make()->warning()->title('Server Suspension')->body($exception->getMessage())->send();
}
Notification::make()->success()->title('Server Unsuspended!')->send();

$this->refreshFormData(['status', 'docker']);
Expand Down
7 changes: 2 additions & 5 deletions app/Services/Servers/SuspensionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Webmozart\Assert\Assert;
use App\Models\Server;
use App\Repositories\Daemon\DaemonServerRepository;
use Doctrine\DBAL\Exception\ConnectionException;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;

class SuspensionService
Expand Down Expand Up @@ -55,11 +56,7 @@ public function handle(Server $server, string $action = self::ACTION_SUSPEND): v
try {
// Tell daemon to re-sync the server state.
$this->daemonServerRepository->setServer($server)->sync();
} catch (\Exception $exception) {
// Rollback the server's suspension status if daemon fails to sync the server.
$server->update([
'status' => $isSuspending ? null : ServerState::Suspended,
]);
} catch (ConnectionException $exception) {
throw $exception;
}
}
Expand Down

0 comments on commit c90d336

Please sign in to comment.