Skip to content

Commit

Permalink
Revert "Apply migration flag check to task manager"
Browse files Browse the repository at this point in the history
This reverts commit a0910eb.
  • Loading branch information
AlanCoding committed Jan 2, 2020
1 parent c6dc69c commit 1f46878
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 36 deletions.
17 changes: 11 additions & 6 deletions awx/main/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.db import IntegrityError
from django.db.migrations.executor import MigrationExecutor
from django.db import IntegrityError, connection
from django.utils.functional import curry
from django.shortcuts import get_object_or_404, redirect
from django.apps import apps
from django.core.cache import cache
from django.utils.deprecation import MiddlewareMixin
from django.utils.translation import ugettext_lazy as _
from django.urls import reverse, resolve

from awx.main.models import ActivityStream
from awx.main.utils.named_url_graph import generate_graph, GraphNode
from awx.main.utils.db import migration_in_progress_check_or_relase
from awx.conf import fields, register


Expand Down Expand Up @@ -213,7 +214,11 @@ def process_request(self, request):
class MigrationRanCheckMiddleware(MiddlewareMixin):

def process_request(self, request):
if migration_in_progress_check_or_relase():
if getattr(resolve(request.path), 'url_name', '') == 'migrations_notran':
return
return redirect(reverse("ui:migrations_notran"))
if cache.get('migration_in_progress', False):
executor = MigrationExecutor(connection)
plan = executor.migration_plan(executor.loader.graph.leaf_nodes())
if not bool(plan):
logger.info('Detected that migration finished, migration page taken down.')
cache.delete('migration_in_progress')
elif getattr(resolve(request.path), 'url_name', '') != 'migrations_notran':
return redirect(reverse("ui:migrations_notran"))
4 changes: 0 additions & 4 deletions awx/main/scheduler/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
# AWX
from awx.main.scheduler import TaskManager
from awx.main.dispatch.publish import task
from awx.main.utils.db import migration_in_progress_check_or_relase

logger = logging.getLogger('awx.main.scheduler')


@task()
def run_task_manager():
if migration_in_progress_check_or_relase():
logger.debug("Not running task manager because migration is in progress.")
return
logger.debug("Running Tower task manager.")
TaskManager().schedule()
26 changes: 0 additions & 26 deletions awx/main/utils/db.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
# Copyright (c) 2017 Ansible by Red Hat
# All Rights Reserved.

import logging
from itertools import chain

from django.core.cache import cache
from django.db.migrations.executor import MigrationExecutor
from django.db import connection


logger = logging.getLogger('awx.main.utils.db')


def get_all_field_names(model):
# Implements compatibility with _meta.get_all_field_names
Expand All @@ -22,21 +14,3 @@ def get_all_field_names(model):
# GenericForeignKey from the results.
if not (field.many_to_one and field.related_model is None)
)))


def migration_in_progress_check_or_relase():
'''A memcache flag is raised (set to True) to inform cluster
that a migration is ongoing see main.apps.MainConfig.ready
if the flag is True then the flag is removed on this instance if
models-db consistency is observed
effective value of migration flag is returned
'''
migration_in_progress = cache.get('migration_in_progress', False)
if migration_in_progress:
executor = MigrationExecutor(connection)
plan = executor.migration_plan(executor.loader.graph.leaf_nodes())
if not bool(plan):
logger.info('Detected that migration finished, migration flag taken down.')
cache.delete('migration_in_progress')
migration_in_progress = False
return migration_in_progress

0 comments on commit 1f46878

Please sign in to comment.