-
Notifications
You must be signed in to change notification settings - Fork 358
[ENG-10768] Have a display of some form when the OSF is down for planned maintenance #11706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
8b91d23
6e3360e
6655865
d49a26e
86784a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| from importlib import import_module | ||
|
|
||
| from django.conf import settings | ||
| from django.http import JsonResponse | ||
| from django.contrib.sessions.middleware import SessionMiddleware | ||
| from django.utils.deprecation import MiddlewareMixin | ||
| from sentry_sdk import init | ||
|
|
@@ -24,6 +25,7 @@ | |
| from .api_globals import api_globals | ||
| from api.base import settings as api_settings | ||
| from api.base.authentication.drf import drf_get_session_from_cookie | ||
| from osf.models import MaintenanceMode | ||
|
|
||
| SessionStore = import_module(settings.SESSION_ENGINE).SessionStore | ||
|
|
||
|
|
@@ -132,3 +134,22 @@ def process_request(self, request): | |
| request.session = drf_get_session_from_cookie(cookie) | ||
| else: | ||
| request.session = SessionStore() | ||
|
|
||
|
|
||
| class MaintenanceModeMiddleware: | ||
| def __init__(self, get_response): | ||
| self.get_response = get_response | ||
|
|
||
| def __call__(self, request): | ||
| if request.path.endswith(('/v2', '/v2/')): | ||
| return self.get_response(request) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see why you did this, based on the ticket, but I don't think this is explicitly necessary. Having the |
||
| if MaintenanceMode.is_under_maintenance(): | ||
| return JsonResponse( | ||
| { | ||
| 'meta': { | ||
| 'maintenance_mode': True, | ||
| 'status_page': 'status', | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is supposed to be |
||
| }, | ||
| }, status=503, | ||
| ) | ||
| return self.get_response(request) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Generated by Django 4.2.26 on 2026-04-23 14:25 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| def create_initial_record(apps, schema_editor): | ||
| MaintenanceMode = apps.get_model('osf', 'MaintenanceMode') | ||
| MaintenanceMode.objects.get_or_create( | ||
| pk=1, | ||
| defaults={'maintenance_mode': False} | ||
| ) | ||
|
|
||
|
|
||
| def reverse_initial_record(apps, schema_editor): | ||
| # the reverse 'reverse_initial_record' does nothing | ||
| # because the table will be removed | ||
| pass | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('osf', '0038_abstractnode_date_last_indexed_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='MaintenanceMode', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('maintenance_mode', models.BooleanField(default=False)), | ||
| ], | ||
| ), | ||
| migrations.RunPython( | ||
| create_initial_record, | ||
| reverse_code=reverse_initial_record | ||
| ), | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super-familiar with Middleware in Django. Will this also prevent incoming requests from being processed (i.e. if someone POSTs or PATCHes something, will we prevent that from affecting the OSF DB)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, middleware calls for all requests and workflow goes to view only if
MaintenanceMode.is_under_maintenance()is False