From f5b0f9fd66fdd645bac478c26270eb7f6fc58687 Mon Sep 17 00:00:00 2001 From: K Muller Date: Thu, 23 Jul 2026 11:09:05 +0200 Subject: [PATCH] fix: :bug: add the queue + env variable --- k8s-queues.sh | 30 ++++++++++++++++++++++++++++++ manifest.yaml | 24 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 k8s-queues.sh diff --git a/k8s-queues.sh b/k8s-queues.sh new file mode 100644 index 0000000..76dd2eb --- /dev/null +++ b/k8s-queues.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# From https://stackoverflow.com/a/76488746/17320077 + +work=true + +function stopQueues() { + echo "Stopping queues..." + work=false + php artisan queue:restart + sleep 45s + exit 0 +} + +# handle graceful shutdown +trap "" SIGPIPE +trap stopQueues EXIT + +echo "Starting PHP queue workers..." + +while $work; do + php artisan queue:work database --queue=default,database --sleep=3 --tries=3 --max-time=3600 --no-interaction + sleep 1 +done + +# Si besoin de plusieurs threads puis terminer par un done sans & +#(while $work; do +# php artisan queue:work --queue="$(grep -oP 'SQS_QUEUE=\K.*' .env)" --no-interaction +# sleep 1 +#done &) diff --git a/manifest.yaml b/manifest.yaml index 46b645d..1f51b4f 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -12,6 +12,7 @@ data: LOG_CHANNEL: "k8s" DB_HOST: "${APP_DB_HOST}" DB_DATABASE: "${APP_DB_DATABASE}" + QUEUE_CONNECTION: "${APP_QUEUE_CONNECTION}" DB_USERNAME: "${APP_DB_USERNAME}" DB_PASSWORD: "${APP_DB_PASSWORD}" MAIL_HOST: "${APP_MAIL_HOST}" @@ -82,6 +83,29 @@ spec: volumeMounts: - name: storage mountPath: /app/srcs/storage + - name: ${CI_PROJECT_PATH_SLUG}-queue-worker + image: $IMAGE_TAG + lifecycle: + preStop: + exec: + command: [ "/bin/sh", "-c", "kill -s TERM 1; while test $(ps ax | grep -v grep | grep bash | wc -l) -gt 0; do sleep 2s; done" ] + resources: + limits: + cpu: "${APP_CI_CPU_LIMIT}" + memory: "${APP_CI_MEMORY_LIMIT}" + requests: + cpu: "${APP_CI_CPU_REQUEST}" + memory: "${APP_CI_MEMORY_REQUEST}" + command: + - "bash" + args: + - "k8s-queues.sh" + envFrom: + - configMapRef: + name: ${CI_PROJECT_PATH_SLUG}-config-map + volumeMounts: + - name: storage + mountPath: /app/srcs/storage imagePullSecrets: - name: docker-registry-credentials securityContext: