1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 23:51:09 +03:00

Start of HA middleware.

This commit is contained in:
Luke Sneeringer 2014-10-01 16:36:34 -05:00
parent 57194c9a89
commit 0e623f2337
3 changed files with 16 additions and 0 deletions

View File

@ -23,3 +23,7 @@ class InstanceManager(models.Manager):
if self.me().primary: if self.me().primary:
return 'primary' return 'primary'
return 'secondary' return 'secondary'
def primary(self):
"""Return the primary instance."""
return self.get(primary=True)

View File

@ -61,3 +61,14 @@ class ActivityStreamMiddleware(threading.local):
else: else:
if instance.id not in self.instance_ids: if instance.id not in self.instance_ids:
self.instance_ids.append(instance.id) self.instance_ids.append(instance.id)
class HAMiddlware(object):
"""A middleware class that checks to see whether the request is being
served on a secondary instance, and redirects the request back to the
primary instance if so.
"""
def process_request(self, request):
"""Process the request, and redirect if this is a request on a
secondary node.
"""

View File

@ -116,6 +116,7 @@ TEMPLATE_CONTEXT_PROCESSORS += (
) )
MIDDLEWARE_CLASSES += ( MIDDLEWARE_CLASSES += (
'awx.main.middleware.HAMiddleware',
'awx.main.middleware.ActivityStreamMiddleware', 'awx.main.middleware.ActivityStreamMiddleware',
'crum.CurrentRequestUserMiddleware', 'crum.CurrentRequestUserMiddleware',
) )