fix: force enable/disable server in case ultimate package quantity decreases

This commit is contained in:
Andras Bacsai
2024-02-26 10:25:21 +01:00
parent 453956172b
commit 678647f39a
25 changed files with 172 additions and 68 deletions

View File

@@ -1675,7 +1675,6 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
);
}
}
$this->next(ApplicationDeploymentStatus::FAILED->value);
}
}

View File

@@ -3,7 +3,8 @@
namespace App\Jobs;
use App\Models\Team;
use App\Notifications\Server\DisabledDueToOverflow;
use App\Notifications\Server\ForceDisabled;
use App\Notifications\Server\ForceEnabled;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -12,7 +13,7 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Queue\SerializesModels;
class ServerOverflowJob implements ShouldQueue, ShouldBeEncrypted
class ServerLimitCheckJob implements ShouldQueue, ShouldBeEncrypted
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@@ -37,26 +38,31 @@ class ServerOverflowJob implements ShouldQueue, ShouldBeEncrypted
public function handle()
{
try {
ray('ServerOverflowJob');
$servers = $this->team->servers;
$servers_count = $servers->count();
$limit = $this->team->limits['serverLimit'];
$number_of_servers_to_disable = $servers_count - $limit;
ray($number_of_servers_to_disable, $servers_count, $limit);
ray('ServerLimitCheckJob', $this->team->uuid, $servers_count, $limit, $number_of_servers_to_disable);
if ($number_of_servers_to_disable > 0) {
ray('Disabling servers');
$servers = $servers->sortBy('created_at');
$servers = $servers->sortbyDesc('created_at');
$servers_to_disable = $servers->take($number_of_servers_to_disable);
$servers_to_disable->each(function ($server) {
$server->disableServerDueToOverflow();
$this->team->notify(new DisabledDueToOverflow($server));
$server->forceDisableServer();
$this->team->notify(new ForceDisabled($server));
});
} else if ($number_of_servers_to_disable === 0) {
$servers->each(function ($server) {
if ($server->isForceDisabled()) {
$server->forceEnableServer();
$this->team->notify(new ForceEnabled($server));
}
});
}
} catch (\Throwable $e) {
send_internal_notification('ServerOverflowJob failed with: ' . $e->getMessage());
send_internal_notification('ServerLimitCheckJob failed with: ' . $e->getMessage());
ray($e->getMessage());
return handleError($e);
}
}
}