Merge pull request #8023 from velzend/improve_logging_migrating_or_instance_not_registered

improve logging migrate or instance not registered
This commit is contained in:
Shane McDonald
2021-07-22 15:50:33 -04:00
committed by GitHub

View File

@@ -97,27 +97,29 @@ class Command(BaseCommand):
executor = MigrationExecutor(connection) executor = MigrationExecutor(connection)
migrating = bool(executor.migration_plan(executor.loader.graph.leaf_nodes())) migrating = bool(executor.migration_plan(executor.loader.graph.leaf_nodes()))
registered = False
if not migrating: # In containerized deployments, migrations happen in the task container,
try: # and the services running there don't start until migrations are
Instance.objects.me() # finished.
registered = True # *This* service runs in the web container, and it's possible that it can
except RuntimeError: # start _before_ migrations are finished, thus causing issues with the ORM
pass # queries it makes (specifically, conf.settings queries).
# This block is meant to serve as a sort of bail-out for the situation
# where migrations aren't yet finished (similar to the migration
# detection middleware that the uwsgi processes have) or when instance
# registration isn't done yet
if migrating:
logger.info('AWX is currently migrating, retry in 10s...')
time.sleep(10)
return
if migrating or not registered: try:
# In containerized deployments, migrations happen in the task container, me = Instance.objects.me()
# and the services running there don't start until migrations are logger.info('Active instance with hostname {} is registered.'.format(me.hostname))
# finished. except RuntimeError as e:
# *This* service runs in the web container, and it's possible that it can # the CLUSTER_HOST_ID in the task, and web instance must match and
# start _before_ migrations are finished, thus causing issues with the ORM # ensure network connectivity between the task and web instance
# queries it makes (specifically, conf.settings queries). logger.info('Unable to return currently active instance: {}, retry in 5s...'.format(e))
# This block is meant to serve as a sort of bail-out for the situation
# where migrations aren't yet finished (similar to the migration
# detection middleware that the uwsgi processes have) or when instance
# registration isn't done yet
logger.error('AWX is currently installing/upgrading. Trying again in 5s...')
time.sleep(5) time.sleep(5)
return return