diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 595e22240..a8a94351e 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -220,7 +220,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted $this->build_server = $this->server; $this->original_server = $this->server; } - ray($this->build_server); try { if ($this->restart_only && $this->application->build_pack !== 'dockerimage') { $this->just_restart(); @@ -311,7 +310,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted } private function push_to_docker_registry($forceFail = false) { - ray((str($this->saved_outputs->get('local_image_found'))->isNotEmpty() && !$this->application->isConfigurationChanged())); if ( $this->application->docker_registry_image_name && $this->application->build_pack !== 'dockerimage' && diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php index b8cabd58b..df92ffaa4 100644 --- a/app/Livewire/Server/Form.php +++ b/app/Livewire/Server/Form.php @@ -27,6 +27,7 @@ class Form extends Component 'server.settings.is_swarm_manager' => 'required|boolean', 'server.settings.is_swarm_worker' => 'required|boolean', 'server.settings.is_build_server' => 'required|boolean', + 'server.settings.concurrent_builds' => 'required|integer', 'wildcard_domain' => 'nullable|url', ]; protected $validationAttributes = [ @@ -40,6 +41,7 @@ class Form extends Component 'server.settings.is_swarm_manager' => 'Swarm Manager', 'server.settings.is_swarm_worker' => 'Swarm Worker', 'server.settings.is_build_server' => 'Build Server', + 'server.settings.concurrent_builds' => 'Concurrent Builds', ]; public function mount() diff --git a/bootstrap/helpers/applications.php b/bootstrap/helpers/applications.php index 6a0eeb01f..02aedb8a7 100644 --- a/bootstrap/helpers/applications.php +++ b/bootstrap/helpers/applications.php @@ -24,8 +24,11 @@ function queue_application_deployment(int $application_id, string $deployment_uu 'commit' => $commit, 'git_type' => $git_type ]); - $queued_deployments = ApplicationDeploymentQueue::where('application_id', $application_id)->where('status', 'queued')->get()->sortByDesc('created_at'); - $running_deployments = ApplicationDeploymentQueue::where('application_id', $application_id)->where('status', 'in_progress')->get()->sortByDesc('created_at'); + $server = Application::find($application_id)->destination->server; + $deployments = ApplicationDeploymentQueue::where('application_id', $application_id); + $queued_deployments = $deployments->where('status', 'queued')->get()->sortByDesc('created_at'); + $running_deployments = $deployments->where('status', 'in_progress')->get()->sortByDesc('created_at'); + $all_deployments = $deployments->where('status', 'queued')->orWhere('status', 'in_progress')->get(); ray('Q:' . $queued_deployments->count() . 'R:' . $running_deployments->count() . '| Queuing deployment: ' . $deployment_uuid . ' of applicationID: ' . $application_id . ' pull request: ' . $pull_request_id . ' with commit: ' . $commit . ' and is it forced: ' . $force_rebuild); if ($queued_deployments->count() > 1) { $queued_deployments = $queued_deployments->skip(1); @@ -37,6 +40,9 @@ function queue_application_deployment(int $application_id, string $deployment_uu if ($running_deployments->count() > 0) { return; } + if ($all_deployments->count() >= $server->settings->concurrent_builds) { + return; + } if ($is_new_deployment) { dispatch(new ApplicationDeploymentNewJob( deployment: $deployment, @@ -51,7 +57,8 @@ function queue_application_deployment(int $application_id, string $deployment_uu function queue_next_deployment(Application $application, bool $isNew = false) { - $next_found = ApplicationDeploymentQueue::where('application_id', $application->id)->where('status', 'queued')->first(); + $next_found = ApplicationDeploymentQueue::where('status', 'queued')->get()->sortByDesc('created_at')->first(); + ray('Next found: ' . $next_found); if ($next_found) { if ($isNew) { dispatch(new ApplicationDeploymentNewJob( diff --git a/database/migrations/2024_01_24_095449_add_concurrent_number_of_builds_per_server.php b/database/migrations/2024_01_24_095449_add_concurrent_number_of_builds_per_server.php new file mode 100644 index 000000000..f10d4891f --- /dev/null +++ b/database/migrations/2024_01_24_095449_add_concurrent_number_of_builds_per_server.php @@ -0,0 +1,28 @@ +integer('concurrent_builds')->default(3); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('server_settings', function (Blueprint $table) { + $table->dropColumn('concurrent_builds'); + }); + } +}; diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php index f801c6444..dd0933e4d 100644 --- a/resources/views/livewire/server/form.blade.php +++ b/resources/views/livewire/server/form.blade.php @@ -86,8 +86,12 @@ @if ($server->isFunctional())