Skip to content

Commit

Permalink
fix: Wait for redis cache and queue to start before starting workers
Browse files Browse the repository at this point in the history
  • Loading branch information
adityahase committed Jun 13, 2024
1 parent 68c9181 commit 4d9e334
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions deployment/supervisor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ directory=/home/frappe/frappe-bench


[program:frappe-bench-frappe-short-worker]
command=/home/frappe/.pyenv/versions/3.10.0/bin/bench worker-pool --num-workers 16 --queue short,default
command=bash -c "/home/frappe/frappe-bench/apps/press/deployment/wait-for-redis.sh && /home/frappe/.pyenv/versions/3.10.0/bin/bench worker-pool --num-workers 16 --queue short,default"
priority=4
autostart=true
autorestart=true
Expand All @@ -43,7 +43,7 @@ process_name=%(program_name)s


[program:frappe-bench-frappe-long-worker]
command=/home/frappe/.pyenv/versions/3.10.0/bin/bench worker-pool --num-workers 16 --queue default,short,long
command=bash -c "/home/frappe/frappe-bench/apps/press/deployment/wait-for-redis.sh && /home/frappe/.pyenv/versions/3.10.0/bin/bench worker-pool --num-workers 16 --queue default,short,long"
priority=4
autostart=true
autorestart=true
Expand All @@ -57,7 +57,7 @@ process_name=%(program_name)s


[program:frappe-bench-frappe-sync-worker]
command=/home/frappe/.pyenv/versions/3.10.0/bin/bench worker-pool --num-workers 6 --queue sync,long,default,short
command=bash -c "/home/frappe/frappe-bench/apps/press/deployment/wait-for-redis.sh && /home/frappe/.pyenv/versions/3.10.0/bin/bench worker-pool --num-workers 6 --queue sync,long,default,short"
priority=4
autostart=true
autorestart=true
Expand All @@ -74,7 +74,7 @@ process_name=%(program_name)s
# Build worker, used to run press side of builds
# i.e tarring and uploading the build context.
[program:frappe-bench-frappe-build-worker]
command=/home/frappe/.pyenv/versions/3.10.0/bin/bench worker-pool --num-workers 8 --queue build
command=bash -c "/home/frappe/frappe-bench/apps/press/deployment/wait-for-redis.sh && /home/frappe/.pyenv/versions/3.10.0/bin/bench worker-pool --num-workers 8 --queue build"
priority=4
autostart=true
autorestart=true
Expand Down
17 changes: 17 additions & 0 deletions deployment/wait-for-it.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

CACHE_URL="redis://127.0.0.1:13000"
QUEUE_URL="redis://127.0.0.1:11000"

MAX_ATTEMPTS=120
attempts=0

until [ $attempts -ge $MAX_ATTEMPTS ]
do
if ( redis-cli -u $QUEUE_URL PING | grep -q PONG ) && ( redis-cli -u $CACHE_URL PING | grep -q PONG ); then
break
fi
sleep 1
echo "Waiting for Redis to be ready..."
((attempts=attempts+1))
done

0 comments on commit 4d9e334

Please sign in to comment.