Skip to content

Commit

Permalink
[OSDEV-1467] Block post api facilities endpoint active switch (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
Innavin369 and Inessa Druzhkova authored Nov 27, 2024
1 parent 814d42e commit d27543a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions doc/release/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ to modify moderation event `status`.
* [OSDEV-1347](https://opensupplyhub.atlassian.net/browse/OSDEV-1347) - Create GET request for `v1/moderation-events/{moderation_id}` endpoint.
* Update `/v1/production-locations/{os_id}` endpoint to return a single object instead of multiple objects. Also, add unit tests for the `ProductionLocationsViewSet`.
* The RDS instance has been upgraded as follows: for `production` and `preprod`, it is now `db.m6in.8xlarge`, and for `test`, it has been upgraded to `db.t3.xlarge`.
* [OSDEV-1467](https://opensupplyhub.atlassian.net/browse/OSDEV-1467) - Implemented disabling endpoint `POST /api/facilities/` during the release process. It is raising an error message with status code 503.

### Architecture/Environment changes
* Increased the memory for the Dedupe Hub instance from 8GB to 12GB in the `production` and `pre-prod` environments to reduce the risk of container overload and minimize the need for reindexing in the future.
Expand Down
3 changes: 3 additions & 0 deletions src/django/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ class NumberOfWorkersRanges:

class ErrorMessages:
GEOCODED_NO_RESULTS = "The address you submitted can not be geocoded."
MAINTENANCE_MODE = ('Open Supply Hub is undergoing maintenance and '
'not accepting new data at the moment. Please '
'try again in a few minutes.')


class FacilitiesDownloadSettings:
Expand Down
4 changes: 2 additions & 2 deletions src/django/api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class BadRequestException(APIException):

class ServiceUnavailableException(APIException):
status_code = status.HTTP_503_SERVICE_UNAVAILABLE
default_detail = 'Service is temporarily unavailable due to maintenance \
work. Please try again later.'
default_detail = ('Service is temporarily unavailable due to maintenance'
'work. Please try again later.')
default_code = 'service_unavailable'
6 changes: 5 additions & 1 deletion src/django/api/views/facility/facilities_view_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from contricleaner.lib.exceptions.handler_not_set_error \
import HandlerNotSetError

from api.exceptions import ServiceUnavailableException
from api.helpers.helpers import validate_workers_count
from oar.settings import (
MAX_ATTACHMENT_SIZE_IN_BYTES,
Expand Down Expand Up @@ -67,7 +68,8 @@
FacilityMergeQueryParams,
ProcessingAction,
UpdateLocationParams,
FacilityClaimStatuses
FacilityClaimStatuses,
ErrorMessages,
)
from ...exceptions import BadRequestException
from ...facility_history import (
Expand Down Expand Up @@ -576,6 +578,8 @@ def create(self, request):
""" # noqa
# Adding the @permission_classes decorator was not working so we
# explicitly invoke our custom permission class.
if switch_is_active('disable_list_uploading'):
raise ServiceUnavailableException(ErrorMessages.MAINTENANCE_MODE)
if not IsRegisteredAndConfirmed().has_permission(request, self):
return Response(status=status.HTTP_401_UNAUTHORIZED)
if not flag_is_active(request._request,
Expand Down
6 changes: 2 additions & 4 deletions src/django/api/views/facility/facility_list_view_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from api.constants import (
FacilityListItemsQueryParams,
ProcessingAction,
ErrorMessages,
)
from api.exceptions import ServiceUnavailableException
from ...facility_history import create_dissociate_match_change_reason
Expand Down Expand Up @@ -92,10 +93,7 @@ def create(self, request):
}
"""
if switch_is_active('disable_list_uploading'):
raise ServiceUnavailableException('Open Supply Hub is undergoing \
maintenance and not accepting new \
data at the moment. Please try again \
in a few minutes.')
raise ServiceUnavailableException(ErrorMessages.MAINTENANCE_MODE)
if 'file' not in request.data:
raise ValidationError('No file specified.')
uploaded_file = request.data['file']
Expand Down

0 comments on commit d27543a

Please sign in to comment.