refactor(github-webhook): restructure application processing by grouping applications by server for improved deployment handling

This commit is contained in:
Andras Bacsai
2025-09-10 09:30:43 +02:00
parent 40f2471c5a
commit 52312e9de6
2 changed files with 266 additions and 254 deletions

View File

@@ -97,7 +97,12 @@ class Github extends Controller
return response("Nothing to do. No applications found with branch '$base_branch'."); return response("Nothing to do. No applications found with branch '$base_branch'.");
} }
} }
foreach ($applications as $application) { $applicationsByServer = $applications->groupBy(function ($app) {
return $app->destination->server_id;
});
foreach ($applicationsByServer as $serverId => $serverApplications) {
foreach ($serverApplications as $application) {
$webhook_secret = data_get($application, 'manual_webhook_secret_github'); $webhook_secret = data_get($application, 'manual_webhook_secret_github');
$hmac = hash_hmac('sha256', $request->getContent(), $webhook_secret); $hmac = hash_hmac('sha256', $request->getContent(), $webhook_secret);
if (! hash_equals($x_hub_signature_256, $hmac) && ! isDev()) { if (! hash_equals($x_hub_signature_256, $hmac) && ! isDev()) {
@@ -257,6 +262,7 @@ class Github extends Controller
} }
} }
} }
}
return response($return_payloads); return response($return_payloads);
} catch (Exception $e) { } catch (Exception $e) {
@@ -358,7 +364,12 @@ class Github extends Controller
return response("Nothing to do. No applications found with branch '$base_branch'."); return response("Nothing to do. No applications found with branch '$base_branch'.");
} }
} }
foreach ($applications as $application) { $applicationsByServer = $applications->groupBy(function ($app) {
return $app->destination->server_id;
});
foreach ($applicationsByServer as $serverId => $serverApplications) {
foreach ($serverApplications as $application) {
$isFunctional = $application->destination->server->isFunctional(); $isFunctional = $application->destination->server->isFunctional();
if (! $isFunctional) { if (! $isFunctional) {
$return_payloads->push([ $return_payloads->push([
@@ -497,6 +508,7 @@ class Github extends Controller
} }
} }
} }
}
return response($return_payloads); return response($return_payloads);
} catch (Exception $e) { } catch (Exception $e) {

View File

@@ -147,7 +147,7 @@ function next_after_cancel(?Server $server = null)
foreach ($next_found as $next) { foreach ($next_found as $next) {
$server = Server::find($next->server_id); $server = Server::find($next->server_id);
$concurrent_builds = $server->settings->concurrent_builds; $concurrent_builds = $server->settings->concurrent_builds;
$inprogress_deployments = ApplicationDeploymentQueue::where('server_id', $next->server_id)->whereIn('status', [ApplicationDeploymentStatus::QUEUED])->get()->sortByDesc('created_at'); $inprogress_deployments = ApplicationDeploymentQueue::where('server_id', $next->server_id)->whereIn('status', [ApplicationDeploymentStatus::IN_PROGRESS])->get()->sortByDesc('created_at');
if ($inprogress_deployments->count() < $concurrent_builds) { if ($inprogress_deployments->count() < $concurrent_builds) {
$next->update([ $next->update([
'status' => ApplicationDeploymentStatus::IN_PROGRESS->value, 'status' => ApplicationDeploymentStatus::IN_PROGRESS->value,