Last active
July 16, 2020 14:33
-
-
Save krishamoud/76a3d4e76ad7da3204473fc7abe1682b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sidekiq: | |
terminationGracePeriodSeconds: 1200 # Max time to wait for sidekiq jobs to finish is 20 minutes | |
container: | |
command: | |
- bundle | |
- exec | |
- sidekiqswarm | |
preStopCMD: ["/bin/bash","/app/bin/sidekiq_graceful_shutdown.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Helper function for printing logs with timestamp | |
echo_time() { | |
date +"[%H:%M:%S] [Sidekiq-graceful-shutdown] $*" | |
} | |
kill -TSTP 1 | |
SIDEKIQ_BUSY=true | |
while $SIDEKIQ_BUSY ; do | |
SIDEKIQ_BUSY=false | |
sidekiq_pids=$(ps aux | grep '[s]idekiq' | grep 'busy' | awk '{print $2}') | |
for pid in $sidekiq_pids ; do | |
IS_SIDEKIQ_DONE=$(ps -f --pid $pid | grep -v PID | grep -E "\[0 of [0-9]+ busy\]" > /dev/null)$? | |
if [ $IS_SIDEKIQ_DONE -ne 0 ]; then | |
echo_time "Sidekiq is still busy" | |
sleep 5 | |
SIDEKIQ_BUSY=true | |
fi | |
done | |
done | |
echo_time "TERM signal - Shutting down sidekiq" | |
kill -TERM 1 2>&1 > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment