From 6e8d0924e41b2b79d5bdecb0904c66529ec72c3d Mon Sep 17 00:00:00 2001 From: Saeed Vaziry Date: Fri, 11 Aug 2023 17:01:46 +0200 Subject: [PATCH] fix realtime update --- .env.prod | 6 ++++- .../Installation/ContinueInstallation.php | 27 ++++++++++++------- app/Jobs/Installation/InstallationJob.php | 3 +-- install/install.sh | 3 +++ package.json | 3 ++- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/.env.prod b/.env.prod index 4678d3e..ea8d52b 100755 --- a/.env.prod +++ b/.env.prod @@ -15,12 +15,16 @@ DB_USERNAME= DB_PASSWORD= BROADCAST_DRIVER=pusher -CACHE_DRIVER=array +CACHE_DRIVER=redis FILESYSTEM_DRIVER=local QUEUE_CONNECTION=default SESSION_DRIVER=database SESSION_LIFETIME=120 +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + MAIL_MAILER=smtp MAIL_HOST=mailhog MAIL_PORT=1025 diff --git a/app/Jobs/Installation/ContinueInstallation.php b/app/Jobs/Installation/ContinueInstallation.php index 9e8f2ad..69d4faa 100644 --- a/app/Jobs/Installation/ContinueInstallation.php +++ b/app/Jobs/Installation/ContinueInstallation.php @@ -11,24 +11,31 @@ class ContinueInstallation extends InstallationJob protected int $attempts; - public function __construct(Server $server) + public function __construct(Server $server, int $attempts = 0) { $this->server = $server; - $this->attempts = 2; + $this->attempts = $attempts; } public function handle(): void { if ($this->server->provider()->isRunning()) { $this->server->install(); - } else { - $this->attempts--; - if ($this->attempts > 0) { - sleep(120); - $this->handle(); - } else { - event(new Broadcast('install-server-failed', $this->server->toArray())); - } + return; } + + if ($this->attempts >= 2) { + $this->server->update([ + 'status' => 'installation_failed', + ]); + event( + new Broadcast('install-server-failed', [ + 'server' => $this->server, + ]) + ); + return; + } + + dispatch(new self($this->server, $this->attempts++))->delay(now()->addMinute()); } } diff --git a/app/Jobs/Installation/InstallationJob.php b/app/Jobs/Installation/InstallationJob.php index b31bcf5..f9d0f07 100755 --- a/app/Jobs/Installation/InstallationJob.php +++ b/app/Jobs/Installation/InstallationJob.php @@ -4,13 +4,12 @@ use App\Jobs\LongJob; use Illuminate\Bus\Queueable; -use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -abstract class InstallationJob implements ShouldQueue, ShouldBeUnique +abstract class InstallationJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use LongJob; diff --git a/install/install.sh b/install/install.sh index 3fc4645..4ff061b 100644 --- a/install/install.sh +++ b/install/install.sh @@ -92,6 +92,9 @@ if ! echo "${V_NGINX_CONFIG}" | tee /etc/nginx/nginx.conf; then fi service nginx start +# redis +apt install redis-server -y + # php export V_PHP_VERSION="8.1" add-apt-repository ppa:ondrej/php -y diff --git a/package.json b/package.json index 5c0c3e3..c67950d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "private": true, "scripts": { "dev": "vite", - "build": "vite build" + "build": "vite build", + "queue:listen": "php artisan queue:listen --timeout=600 --queue=default,ssh,ssh-long" }, "devDependencies": { "@ryangjchandler/alpine-clipboard": "^2.2.0",