Page MenuHomePhabricator

Wait for blocking tasks to finish before running next container script
Open, MediumPublic

Description

When the tool is brought up for the first time the database takes a little while to start up, but Docker Compose won't natively wait for the database to finish setup before starting to run the Django app. This results in the app not being able to connect successfully and erroring out. The Scripts container then has the same problem connecting to the app - migrations need to finish running before the script can find the right database table.

To avoid this for now, simply wait for the build to finish, then re-build the containers twice. We should develop a better solution though.

See https://docs.docker.com/compose/startup-order/

The simplest solution would be editing gunicorn.sh and collect_hashtags.py to wait for their dependencies to be ready before running.

Event Timeline

This comment was removed by Samwalton9.
Samwalton9 renamed this task from Wait for database to start before running anything that requires it to Wait for blocking tasks to finish before running next container script.Oct 24 2018, 10:50 AM
Samwalton9 updated the task description. (Show Details)

The app now waits for mysqladmin to return a valid ping before attempting to start and migrate (https://github.com/Samwalton9/hashtags/commit/cebaefec0f8e6bb24dca3648b652306cf4c7c77f).

Still need to fix the script not connecting, but that requires a slightly different fix.

Specifically, the script needs to check that the hashtags_hashtag table exists, and that migrations have finished running, before starting, which is a much more involved check.

Samwalton9 triaged this task as Medium priority.Dec 20 2018, 9:39 PM

Can this be referenced here ? - https://github.com/Samwalton9/hashtags/issues/26

I got issues while building with docker and had to build it twice for the app to load.

That Github issue doesn't appear to be relevant as it turned out to be a firewall conflict.

Additionally, the first step (app not starting because db isn't ready) should now be fixed by the health check. The remaining step is having the script container wait for migrations to finish on the app container.