From 8991de26107343b6de0a04df134732acf0208dbb Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 31 May 2023 14:57:42 +0200 Subject: [PATCH] fixes --- app/Http/Livewire/Project/Application/Deployments.php | 8 ++++---- app/Http/Livewire/Project/Application/Preview/Form.php | 1 - app/Http/Livewire/Project/Application/Previews.php | 4 ++-- app/Jobs/ApplicationDeploymentJob.php | 4 +--- app/Jobs/ContainerStatusJob.php | 3 +-- app/Models/Application.php | 9 +++++++-- bootstrap/helpers/applications.php | 2 +- .../livewire/project/application/deployments.blade.php | 8 ++++---- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/Http/Livewire/Project/Application/Deployments.php b/app/Http/Livewire/Project/Application/Deployments.php index 3ab123635..3002051d8 100644 --- a/app/Http/Livewire/Project/Application/Deployments.php +++ b/app/Http/Livewire/Project/Application/Deployments.php @@ -9,6 +9,7 @@ class Deployments extends Component { public int $application_id; public $deployments = []; + public int $deployments_count = 0; public string $current_url; public int $skip = 0; public int $default_take = 8; @@ -24,15 +25,14 @@ public function reload_deployments() } public function load_deployments(int|null $take = null) { - ray('Take' . $take); if ($take) { - ray('Take is not null'); $this->skip = $this->skip + $take; } $take = $this->default_take; - $this->deployments = Application::find($this->application_id)->deployments($this->skip, $take); - + ['deployments' => $deployments, 'count' => $count] = Application::find($this->application_id)->deployments($this->skip, $take); + $this->deployments = $deployments; + $this->deployments_count = $count; if (count($this->deployments) !== 0 && count($this->deployments) < $take) { $this->show_next = false; return; diff --git a/app/Http/Livewire/Project/Application/Preview/Form.php b/app/Http/Livewire/Project/Application/Preview/Form.php index a7a718592..9cdac681b 100644 --- a/app/Http/Livewire/Project/Application/Preview/Form.php +++ b/app/Http/Livewire/Project/Application/Preview/Form.php @@ -37,7 +37,6 @@ public function submit() { $this->validate(); $this->application->preview_url_template = str_replace(' ', '', $this->application->preview_url_template); - ray($this->application->preview_url_template); $this->application->save(); $this->generate_real_url(); } diff --git a/app/Http/Livewire/Project/Application/Previews.php b/app/Http/Livewire/Project/Application/Previews.php index 4c1e8ff10..4a3af6761 100644 --- a/app/Http/Livewire/Project/Application/Previews.php +++ b/app/Http/Livewire/Project/Application/Previews.php @@ -41,12 +41,12 @@ public function load_prs() $this->rate_limit_remaining = $rate_limit_remaining; $this->pull_requests = $data->sortBy('number')->values(); } - public function deploy(int $pull_request_id, string|null $pull_request_html_url) + public function deploy(int $pull_request_id, string|null $pull_request_html_url = null) { try { $this->set_deployment_uuid(); $found = ApplicationPreview::where('application_id', $this->application->id)->where('pull_request_id', $pull_request_id)->first(); - if (!$found) { + if (!$found && !is_null($pull_request_html_url)) { ApplicationPreview::create([ 'application_id' => $this->application->id, 'pull_request_id' => $pull_request_id, diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 655d4b620..eea7c9f24 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -269,7 +269,6 @@ public function failed(): void private function next(string $status) { - ray($this->application_deployment_queue->status, Str::of($this->application_deployment_queue->status)->startsWith('cancelled')); if (!Str::of($this->application_deployment_queue->status)->startsWith('cancelled')) { $this->application_deployment_queue->update([ 'status' => $status, @@ -522,7 +521,7 @@ private function execute_now( } else { $commandText = collect($command)->implode("\n"); } - ray('Executing command', $commandText); + ray('Executing command: ' . $commandText); $this->activity->properties = $this->activity->properties->merge([ 'command' => $commandText, ]); @@ -623,7 +622,6 @@ private function nixpacks_build_cmd() $nixpacks_command .= " --install-cmd \"{$this->application->install_command}\""; } $nixpacks_command .= " {$this->workdir}"; - ray('Build command: ' . $nixpacks_command); return $this->execute_in_builder($nixpacks_command); } private function stop_running_container() diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index b53de6209..9ff18f9ba 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -34,9 +34,8 @@ public function uniqueId(): string public function handle(): void { try { - ray('running ContainerStatusJob', $this->container_name, $this->pull_request_id); $status = get_container_status(server: $this->application->destination->server, container_id: $this->container_name, throwError: false); - ray('ContainerStatusJob', $status); + ray('Container ' . $this->container_name . ' statuus is ' . $status); if ($this->pull_request_id) { $preview = ApplicationPreview::findPreviewByApplicationAndPullId($this->application->id, $this->pull_request_id); $preview->status = $status; diff --git a/app/Models/Application.php b/app/Models/Application.php index 46f7956a1..da41e4056 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -146,8 +146,13 @@ public function persistentStorages() public function deployments(int $skip = 0, int $take = 10) { - ray('Skip ' . $skip . ' Take ' . $take); - return ApplicationDeploymentQueue::where('application_id', $this->id)->orderBy('created_at', 'desc')->skip($skip)->take($take)->get(); + $deployments = ApplicationDeploymentQueue::where('application_id', $this->id)->orderBy('created_at', 'desc'); + $count = $deployments->count(); + $deployments = $deployments->skip($skip)->take($take)->get(); + return [ + 'count' => $count, + 'deployments' => $deployments + ]; } public function get_deployment(string $deployment_uuid) { diff --git a/bootstrap/helpers/applications.php b/bootstrap/helpers/applications.php index ac65607fb..3a1332e93 100644 --- a/bootstrap/helpers/applications.php +++ b/bootstrap/helpers/applications.php @@ -16,7 +16,7 @@ function queue_application_deployment(int $application_id, string $deployment_uu ]); $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'); - 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); + 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); $queued_deployments->each(function ($queued_deployment, $key) { diff --git a/resources/views/livewire/project/application/deployments.blade.php b/resources/views/livewire/project/application/deployments.blade.php index 53b1685cf..9878fb221 100644 --- a/resources/views/livewire/project/application/deployments.blade.php +++ b/resources/views/livewire/project/application/deployments.blade.php @@ -3,13 +3,13 @@

Actions

@if ($show_next) - Load More + Load Previous Deployments @else No More Deployments @endif
-

Deployments

+

Deployments ({{ $deployments_count }})

@foreach ($deployments as $deployment)
- {{ $deployment->deployment_uuid }} > + {{ $deployment->id }} > {{ $deployment->deployment_uuid }} > {{ $deployment->status }}
@if (data_get($deployment, 'pull_request_id')) @@ -47,7 +48,6 @@ class="hover:no-underline"> @endif
@endif -
Finished 0s in 0s