diff --git a/edrop-cron.sh b/edrop-cron.sh index 73d2cc0..869a339 100755 --- a/edrop-cron.sh +++ b/edrop-cron.sh @@ -15,5 +15,21 @@ export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE export PYTHONPATH=$DJANGODIR:$PYTHONPATH mkdir -p /edrop/logs +# When a new container is being created, eDROP Connector takes a long time to startup because all dependencies +# need to be installed first. The cron job, however, needs all dependencies to be installed before it can start up. +# Since we know that once eDROP Connector is up and running, all dependencies are installed, we just wait till we +# get a 200 response from the web app before starting the cron job. +# Using the autorestart property of Supervisor does not seem to work when deployed in production, hence this work around. +while true; do + sleep 5; + http_response=$(curl -s -o /dev/null -I -w "%{http_code}\n" http://localhost:8000/$APP_ROOT); + if [ $http_response == "200" ]; then + break + else + echo "eDROP Connector is not yet responding." + fi +done +echo "eDROP Connector has started successfully" + # start the cron job python manage.py runapscheduler \ No newline at end of file diff --git a/supervisord.conf b/supervisord.conf index 652ed69..da1fe45 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -22,7 +22,7 @@ stopasgroup=true ; if rabbitmq is supervised, set its priority higher ; so it starts first -priority=998 +priority=997 [program:edrop-cron] command=/edrop/edrop-cron.sh