Last active
June 10, 2019 13:59
-
-
Save ndbroadbent/ea32c513f43917a844903760831ec9d3 to your computer and use it in GitHub Desktop.
sidekiq_sanity_check_2.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 | |
set -e | |
if [ -f .env ]; then spring stop; fi | |
# This script is run in the CI build. It requires a REDIS_URL variable, | |
# and runs a test job through the WorkerHealthCheckJob. | |
# I added this check after I accidentally pushed a change that caused the sidekiq | |
# workers to crash on boot. The jobs were well-tested, but the actual | |
# sidekiq config had an error inside a #configure_server block, so the code | |
# only crashed when I started an actual Sidekiq worker process. | |
SIDEKIQ_RESULT_FILE="/tmp/sidekiq-worker-test.txt" | |
echo "Starting Sidekiq process..." | |
# pidfile / logfile / daemon options will be removed in Sidekiq 6 | |
# See: https://github.com/mperham/sidekiq/issues/4045 | |
sidekiq & | |
SIDEKIQ_PID=$(echo $!) | |
rm -rf "$SIDEKIQ_RESULT_FILE" | |
RANDOM_STRING=$(openssl rand -hex 32) | |
echo "Creating a WorkerHealthCheckJob job via rails runner..." | |
./bin/rails runner "WorkerHealthCheckJob.perform_async('$RANDOM_STRING')" | |
SUCCESS="no" | |
RETRY_COUNT=0 | |
echo "Waiting for $SIDEKIQ_RESULT_FILE to contain $RANDOM_STRING..." | |
while [ ! -f "$SIDEKIQ_RESULT_FILE" ]; do | |
if [ $RETRY_COUNT -gt 20 ]; then | |
echo "Did not find $SIDEKIQ_RESULT_FILE after 20 seconds!" | |
break | |
fi | |
RETRY_COUNT=$((RETRY_COUNT+1)) | |
sleep 1 | |
done | |
if [ -f "$SIDEKIQ_RESULT_FILE" ]; then | |
RESULT_CONTENTS=$(cat "$SIDEKIQ_RESULT_FILE") | |
if [ "$RESULT_CONTENTS" == "$RANDOM_STRING" ]; then | |
echo "Success!" | |
SUCCESS="yes" | |
else | |
echo "$SIDEKIQ_RESULT_FILE contents did not match the expected string!" | |
echo "Contents: '$RESULT_CONTENTS'" | |
echo "Expected: '$RANDOM_STRING'" | |
fi | |
fi | |
echo "Killing Sidekiq process ($SIDEKIQ_PID)..." | |
kill -9 "$SIDEKIQ_PID" | |
rm -rf "$SIDEKIQ_RESULT_FILE" | |
if [ "$SUCCESS" != "yes" ]; then exit 1; fi | |
if [ -f .env ]; then spring stop; fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment