Skip to content

Commit

Permalink
Gracefully stop workers.
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanzdosilovic committed Sep 15, 2019
1 parent 121c8f9 commit 2ae0cd3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions scripts/run-workers
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/bin/bash
source ./scripts/load-config
while true; do
COUNT=${COUNT:-1} rails resque:workers

run_resque=1
resque_pid=0

exit_gracefully() {
run_resque=0
kill -SIGQUIT $(pgrep -P $resque_pid)
kill -SIGTERM $resque_pid
}

trap exit_gracefully SIGTERM SIGINT

mkdir -p tmp/pids &> /dev/null
while [[ $run_resque -eq 1 ]]; do
rm -rf tmp/pids/resque.pid &> /dev/null
COUNT=${COUNT:-1} rails resque:workers &
resque_pid=$!
while ps -p $resque_pid > /dev/null; do sleep 1s; done
done

0 comments on commit 2ae0cd3

Please sign in to comment.