From 3007b06dc6c67b5174b93e6b60dd9b25ef1d399d Mon Sep 17 00:00:00 2001 From: Marvin Roman Date: Thu, 16 Nov 2023 02:16:10 -0800 Subject: [PATCH] ci(deploy): add command & queue to put site into maintenance and bring back up after delay --- .kube/app/entrypoint.sh | 4 +- .kube/app/supervisord.conf | 9 +++++ .kube/app/values.development.yaml | 2 +- .kube/app/values.production.yaml | 2 +- .kube/app/values.staging.yaml | 2 +- .kube/app/values.yaml | 2 +- .../Commands/MaintenanceModeQueueCommand.php | 37 +++++++++++++++++++ .../PreventRequestsDuringMaintenance.php | 3 +- app/Jobs/BringSiteBackUp.php | 31 ++++++++++++++++ 9 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 app/Console/Commands/MaintenanceModeQueueCommand.php create mode 100644 app/Jobs/BringSiteBackUp.php diff --git a/.kube/app/entrypoint.sh b/.kube/app/entrypoint.sh index 86897f692..32401ea0c 100755 --- a/.kube/app/entrypoint.sh +++ b/.kube/app/entrypoint.sh @@ -2,6 +2,8 @@ set -e +php artisan maintenance:queue + # TODO permanent remove cache lines once testing on per/pod caching is tested mkdir -p $FILES_PATH @@ -26,7 +28,7 @@ ln -s $FILES_PATH /app/storage php artisan deploy:local -flock -n -E 0 /opt/data -c "php artisan deploy:global" # run exclusively on a single instance at once +flock -n -E 0 /opt/data/deploy-global.lock -c "php artisan deploy:global" # run exclusively on a single instance at once ## fix permissions after syncing to existing storage and cache https://github.com/accessibility-exchange/platform/issues/1236 chown -R www-data:root /app/bootstrap/cache $FILES_PATH # $CACHE_PATH removed per and added path to cache in the pod https://github.com/accessibility-exchange/platform/issues/1596 diff --git a/.kube/app/supervisord.conf b/.kube/app/supervisord.conf index da022d0c2..a24fcbbad 100644 --- a/.kube/app/supervisord.conf +++ b/.kube/app/supervisord.conf @@ -24,3 +24,12 @@ stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 + +[program:laravel-worker] +command=php /app/artisan queue:work --force --sleep=30 --tries=3 --max-time=900 +autostart=true +autorestart=false +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 diff --git a/.kube/app/values.development.yaml b/.kube/app/values.development.yaml index ea3fd8638..1680a38ac 100644 --- a/.kube/app/values.development.yaml +++ b/.kube/app/values.development.yaml @@ -13,7 +13,7 @@ env: LOG_LEVEL: "debug" BROADCAST_DRIVER: "log" CACHE_DRIVER: "file" - QUEUE_CONNECTION: "sync" + QUEUE_CONNECTION: "redis" SESSION_DRIVER: "database" SESSION_LIFETIME: "120" SAIL_XDEBUG_MODE: "develop,debug,coverage" diff --git a/.kube/app/values.production.yaml b/.kube/app/values.production.yaml index b587b99ae..2bb92c556 100644 --- a/.kube/app/values.production.yaml +++ b/.kube/app/values.production.yaml @@ -13,7 +13,7 @@ env: LOG_LEVEL: "debug" BROADCAST_DRIVER: "log" CACHE_DRIVER: "file" - QUEUE_CONNECTION: "sync" + QUEUE_CONNECTION: "redis" SESSION_DRIVER: "database" SESSION_LIFETIME: "120" SAIL_XDEBUG_MODE: "develop,debug,coverage" diff --git a/.kube/app/values.staging.yaml b/.kube/app/values.staging.yaml index 019f27aba..384bd8f3b 100644 --- a/.kube/app/values.staging.yaml +++ b/.kube/app/values.staging.yaml @@ -13,7 +13,7 @@ env: LOG_LEVEL: "debug" BROADCAST_DRIVER: "log" CACHE_DRIVER: "file" - QUEUE_CONNECTION: "sync" + QUEUE_CONNECTION: "redis" SESSION_DRIVER: "database" SESSION_LIFETIME: "120" SAIL_XDEBUG_MODE: "develop,debug,coverage" diff --git a/.kube/app/values.yaml b/.kube/app/values.yaml index 10e9ad018..2dfb65322 100644 --- a/.kube/app/values.yaml +++ b/.kube/app/values.yaml @@ -1,5 +1,5 @@ name: "IRIS Accessibility Exchange" -health: / +health: /status/db cronjobs: - name: schedule schedule: "* * * * *" diff --git a/app/Console/Commands/MaintenanceModeQueueCommand.php b/app/Console/Commands/MaintenanceModeQueueCommand.php new file mode 100644 index 000000000..f6c54765c --- /dev/null +++ b/app/Console/Commands/MaintenanceModeQueueCommand.php @@ -0,0 +1,37 @@ +call('down'); + + // Schedule bringing the site back up after 5 minutes + BringSiteBackUp::dispatch()->delay(now()->addMinutes(5)); + + $this->info('The site is in maintenance mode. It will be brought back up in 5 minutes.'); + } +} diff --git a/app/Http/Middleware/PreventRequestsDuringMaintenance.php b/app/Http/Middleware/PreventRequestsDuringMaintenance.php index 74cbd9a9e..b3d9d279f 100644 --- a/app/Http/Middleware/PreventRequestsDuringMaintenance.php +++ b/app/Http/Middleware/PreventRequestsDuringMaintenance.php @@ -12,6 +12,7 @@ class PreventRequestsDuringMaintenance extends Middleware * @var array */ protected $except = [ - // + 'status', + 'status/db', ]; } diff --git a/app/Jobs/BringSiteBackUp.php b/app/Jobs/BringSiteBackUp.php new file mode 100644 index 000000000..13c58a0e7 --- /dev/null +++ b/app/Jobs/BringSiteBackUp.php @@ -0,0 +1,31 @@ +