From ea7c4c26cece7d5a84dd32b048d156b1421523e1 Mon Sep 17 00:00:00 2001 From: Ben Larabie Date: Wed, 11 Oct 2023 13:40:16 -0400 Subject: [PATCH 1/3] Reworking the celery init on k8s so I can see logging --- scripts/run_celery.sh | 18 ++++++------------ scripts/run_celery_no_sms_sending.sh | 23 +++++++++-------------- scripts/run_celery_send_sms.sh | 16 +++++----------- scripts/run_celery_sms.sh | 18 ++++++------------ 4 files changed, 26 insertions(+), 49 deletions(-) diff --git a/scripts/run_celery.sh b/scripts/run_celery.sh index ad8635791b..361c4e8887 100755 --- a/scripts/run_celery.sh +++ b/scripts/run_celery.sh @@ -2,27 +2,21 @@ # runs celery with all celery queues except the throtted sms queue -init() -{ - # Wait for cwagent to become available. +set -e +# Check and see if this is running in K8s and if so, wait for cloudwatch agent +if [[ -z "${STATSD_HOST}" ]]; then + echo "Initializing... Waiting for CWAgent to become ready." while : do if nc -vz $STATSD_HOST 25888; then - echo "CWAgent is Ready." + echo "CWAgent is Ready." > /dev/stderr break; else - echo "Waiting for CWAgent to become ready." + echo "Waiting for CWAgent to become ready." > /dev/stderr sleep 1 fi done -} - -set -e - -# Check and see if this is running in K8s and if so, wait for cloudwatch agent -if [[ -z "${STATSD_HOST}" ]]; then - init fi echo "Start celery, concurrency: ${CELERY_CONCURRENCY-4}" diff --git a/scripts/run_celery_no_sms_sending.sh b/scripts/run_celery_no_sms_sending.sh index f0669c7d39..695bbb74f7 100755 --- a/scripts/run_celery_no_sms_sending.sh +++ b/scripts/run_celery_no_sms_sending.sh @@ -2,28 +2,23 @@ # runs celery with only the throttled sms sending queue -init() -{ - # Wait for cwagent to become available. +# runs celery with all celery queues except send-throttled-sms-tasks, send-sms-tasks, send-sms-high, send-sms-medium, or send-sms-low + +set -e + +# Check and see if this is running in K8s and if so, wait for cloudwatch agent +if [[ -z "${STATSD_HOST}" ]]; then + echo "Initializing... Waiting for CWAgent to become ready." while : do if nc -vz $STATSD_HOST 25888; then - echo "CWAgent is Ready." + echo "CWAgent is Ready." > /dev/stderr break; else - echo "Waiting for CWAgent to become ready." + echo "Waiting for CWAgent to become ready." > /dev/stderr sleep 1 fi done -} - -# runs celery with all celery queues except send-throttled-sms-tasks, send-sms-tasks, send-sms-high, send-sms-medium, or send-sms-low - -set -e - -# Check and see if this is running in K8s and if so, wait for cloudwatch agent -if [[ -z "${STATSD_HOST}" ]]; then - init fi echo "Start celery, concurrency: ${CELERY_CONCURRENCY-4}" diff --git a/scripts/run_celery_send_sms.sh b/scripts/run_celery_send_sms.sh index e6c32a5d75..ce7d888fab 100755 --- a/scripts/run_celery_send_sms.sh +++ b/scripts/run_celery_send_sms.sh @@ -1,26 +1,20 @@ #!/bin/sh # runs celery with only the send-sms-* queues +set -e -init() -{ - # Wait for cwagent to become available. +if [[ -z "${STATSD_HOST}" ]]; then + echo "Initializing... Waiting for CWAgent to become ready." while : do if nc -vz $STATSD_HOST 25888; then - echo "CWAgent is Ready." + echo "CWAgent is Ready." > /dev/stderr break; else - echo "Waiting for CWAgent to become ready." + echo "Waiting for CWAgent to become ready." > /dev/stderr sleep 1 fi done -} - -set -e - -if [[ -z "${STATSD_HOST}" ]]; then - init fi echo "Start celery, concurrency: ${CELERY_CONCURRENCY-4}" diff --git a/scripts/run_celery_sms.sh b/scripts/run_celery_sms.sh index 583fab7127..970796d751 100755 --- a/scripts/run_celery_sms.sh +++ b/scripts/run_celery_sms.sh @@ -2,26 +2,20 @@ # runs celery with only the throttled sms sending queue -init() -{ - # Wait for cwagent to become available. +set -e + +if [[ -z "${STATSD_HOST}" ]]; then + echo "Initializing... Waiting for CWAgent to become ready." while : do if nc -vz $STATSD_HOST 25888; then - echo "CWAgent is Ready." + echo "CWAgent is Ready." > /dev/stderr break; else - echo "Waiting for CWAgent to become ready." + echo "Waiting for CWAgent to become ready." > /dev/stderr sleep 1 fi done -} - -set -e - -# Check and see if this is running in K8s and if so, wait for cloudwatch agent -if [[ -z "${STATSD_HOST}" ]]; then - init fi celery -A run_celery.notify_celery worker --loglevel=INFO --concurrency=1 -Q send-throttled-sms-tasks From 243e395499d29d877b06cdfd4eb4ea79d27d1ec0 Mon Sep 17 00:00:00 2001 From: Ben Larabie Date: Wed, 11 Oct 2023 13:53:15 -0400 Subject: [PATCH 2/3] Removing the redirect to stderr which was put there by mistake --- scripts/run_celery.sh | 4 ++-- scripts/run_celery_no_sms_sending.sh | 4 ++-- scripts/run_celery_send_sms.sh | 4 ++-- scripts/run_celery_sms.sh | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/run_celery.sh b/scripts/run_celery.sh index 361c4e8887..2b3d4a1bc0 100755 --- a/scripts/run_celery.sh +++ b/scripts/run_celery.sh @@ -10,10 +10,10 @@ if [[ -z "${STATSD_HOST}" ]]; then while : do if nc -vz $STATSD_HOST 25888; then - echo "CWAgent is Ready." > /dev/stderr + echo "CWAgent is Ready." break; else - echo "Waiting for CWAgent to become ready." > /dev/stderr + echo "Waiting for CWAgent to become ready." sleep 1 fi done diff --git a/scripts/run_celery_no_sms_sending.sh b/scripts/run_celery_no_sms_sending.sh index 695bbb74f7..f0fe622681 100755 --- a/scripts/run_celery_no_sms_sending.sh +++ b/scripts/run_celery_no_sms_sending.sh @@ -12,10 +12,10 @@ if [[ -z "${STATSD_HOST}" ]]; then while : do if nc -vz $STATSD_HOST 25888; then - echo "CWAgent is Ready." > /dev/stderr + echo "CWAgent is Ready." break; else - echo "Waiting for CWAgent to become ready." > /dev/stderr + echo "Waiting for CWAgent to become ready." sleep 1 fi done diff --git a/scripts/run_celery_send_sms.sh b/scripts/run_celery_send_sms.sh index ce7d888fab..ee0101cdd4 100755 --- a/scripts/run_celery_send_sms.sh +++ b/scripts/run_celery_send_sms.sh @@ -8,10 +8,10 @@ if [[ -z "${STATSD_HOST}" ]]; then while : do if nc -vz $STATSD_HOST 25888; then - echo "CWAgent is Ready." > /dev/stderr + echo "CWAgent is Ready." break; else - echo "Waiting for CWAgent to become ready." > /dev/stderr + echo "Waiting for CWAgent to become ready." sleep 1 fi done diff --git a/scripts/run_celery_sms.sh b/scripts/run_celery_sms.sh index 970796d751..0afca890d2 100755 --- a/scripts/run_celery_sms.sh +++ b/scripts/run_celery_sms.sh @@ -9,10 +9,10 @@ if [[ -z "${STATSD_HOST}" ]]; then while : do if nc -vz $STATSD_HOST 25888; then - echo "CWAgent is Ready." > /dev/stderr + echo "CWAgent is Ready." break; else - echo "Waiting for CWAgent to become ready." > /dev/stderr + echo "Waiting for CWAgent to become ready." sleep 1 fi done From 0a30a7e6eefcebb9d86ff1787dfc040ab6fb9dd7 Mon Sep 17 00:00:00 2001 From: Ben Larabie Date: Wed, 11 Oct 2023 15:25:04 -0400 Subject: [PATCH 3/3] Inverting if condition --- scripts/run_celery.sh | 2 +- scripts/run_celery_no_sms_sending.sh | 5 ++--- scripts/run_celery_send_sms.sh | 2 +- scripts/run_celery_sms.sh | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/run_celery.sh b/scripts/run_celery.sh index 2b3d4a1bc0..e8f52e8283 100755 --- a/scripts/run_celery.sh +++ b/scripts/run_celery.sh @@ -5,7 +5,7 @@ set -e # Check and see if this is running in K8s and if so, wait for cloudwatch agent -if [[ -z "${STATSD_HOST}" ]]; then +if [[ ! -z "${STATSD_HOST}" ]]; then echo "Initializing... Waiting for CWAgent to become ready." while : do diff --git a/scripts/run_celery_no_sms_sending.sh b/scripts/run_celery_no_sms_sending.sh index f0fe622681..19d497ee60 100755 --- a/scripts/run_celery_no_sms_sending.sh +++ b/scripts/run_celery_no_sms_sending.sh @@ -7,7 +7,7 @@ set -e # Check and see if this is running in K8s and if so, wait for cloudwatch agent -if [[ -z "${STATSD_HOST}" ]]; then +if [[ ! -z "${STATSD_HOST}" ]]; then echo "Initializing... Waiting for CWAgent to become ready." while : do @@ -18,8 +18,7 @@ if [[ -z "${STATSD_HOST}" ]]; then echo "Waiting for CWAgent to become ready." sleep 1 fi - done -fi + done fi echo "Start celery, concurrency: ${CELERY_CONCURRENCY-4}" diff --git a/scripts/run_celery_send_sms.sh b/scripts/run_celery_send_sms.sh index ee0101cdd4..7146d46b0c 100755 --- a/scripts/run_celery_send_sms.sh +++ b/scripts/run_celery_send_sms.sh @@ -3,7 +3,7 @@ # runs celery with only the send-sms-* queues set -e -if [[ -z "${STATSD_HOST}" ]]; then +if [[ ! -z "${STATSD_HOST}" ]]; then echo "Initializing... Waiting for CWAgent to become ready." while : do diff --git a/scripts/run_celery_sms.sh b/scripts/run_celery_sms.sh index 0afca890d2..1c63607585 100755 --- a/scripts/run_celery_sms.sh +++ b/scripts/run_celery_sms.sh @@ -4,7 +4,7 @@ set -e -if [[ -z "${STATSD_HOST}" ]]; then +if [[ ! -z "${STATSD_HOST}" ]]; then echo "Initializing... Waiting for CWAgent to become ready." while : do