mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 15:21:13 +03:00
Reduce API response times by caching migration flag
This commit is contained in:
parent
04c535e3f9
commit
5433af6716
@ -1,8 +1,17 @@
|
|||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
from django.db.models.signals import pre_migrate
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
def raise_migration_flag(**kwargs):
|
||||||
|
from awx.main.tasks import set_migration_flag
|
||||||
|
set_migration_flag.delay()
|
||||||
|
|
||||||
|
|
||||||
class MainConfig(AppConfig):
|
class MainConfig(AppConfig):
|
||||||
|
|
||||||
name = 'awx.main'
|
name = 'awx.main'
|
||||||
verbose_name = _('Main')
|
verbose_name = _('Main')
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
pre_migrate.connect(raise_migration_flag, sender=self)
|
||||||
|
@ -18,6 +18,7 @@ from django.db import IntegrityError, connection
|
|||||||
from django.utils.functional import curry
|
from django.utils.functional import curry
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
from django.core.cache import cache
|
||||||
from django.utils.deprecation import MiddlewareMixin
|
from django.utils.deprecation import MiddlewareMixin
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.urls import reverse, resolve
|
from django.urls import reverse, resolve
|
||||||
@ -213,8 +214,11 @@ class URLModificationMiddleware(MiddlewareMixin):
|
|||||||
class MigrationRanCheckMiddleware(MiddlewareMixin):
|
class MigrationRanCheckMiddleware(MiddlewareMixin):
|
||||||
|
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
|
if cache.get('migration_in_progress', False):
|
||||||
executor = MigrationExecutor(connection)
|
executor = MigrationExecutor(connection)
|
||||||
plan = executor.migration_plan(executor.loader.graph.leaf_nodes())
|
plan = executor.migration_plan(executor.loader.graph.leaf_nodes())
|
||||||
if bool(plan) and \
|
if not bool(plan):
|
||||||
getattr(resolve(request.path), 'url_name', '') != 'migrations_notran':
|
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"))
|
return redirect(reverse("ui:migrations_notran"))
|
||||||
|
@ -263,6 +263,12 @@ def apply_cluster_membership_policies():
|
|||||||
logger.debug('Cluster policy computation finished in {} seconds'.format(time.time() - started_compute))
|
logger.debug('Cluster policy computation finished in {} seconds'.format(time.time() - started_compute))
|
||||||
|
|
||||||
|
|
||||||
|
@task(queue='tower_broadcast_all', exchange_type='fanout')
|
||||||
|
def set_migration_flag():
|
||||||
|
logger.debug('Received migration-in-progress signal, will serve redirect.')
|
||||||
|
cache.set('migration_in_progress', True)
|
||||||
|
|
||||||
|
|
||||||
@task(queue='tower_broadcast_all', exchange_type='fanout')
|
@task(queue='tower_broadcast_all', exchange_type='fanout')
|
||||||
def handle_setting_changes(setting_keys):
|
def handle_setting_changes(setting_keys):
|
||||||
orig_len = len(setting_keys)
|
orig_len = len(setting_keys)
|
||||||
|
Loading…
Reference in New Issue
Block a user