Skip to content

Set brownouts for deprecated embed API v2 #11786

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

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion readthedocs/embed/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Views for the embed app."""

import datetime
import json
import re

import pytz
import structlog
from django.conf import settings
from django.template.defaultfilters import slugify
from docutils.nodes import make_id
from pyquery import PyQuery as PQ # noqa
Expand Down Expand Up @@ -66,8 +68,39 @@ def external(self):
# Always return False because APIv2 does not support external domains
return False

def _is_disabled_for_deprecation(self):
if settings.RTD_ENFORCE_BROWNOUTS_FOR_DEPRECATIONS:
return False

tzinfo = pytz.timezone("America/Los_Angeles")
now = datetime.datetime.now(tz=tzinfo)
# Dates as per https://about.readthedocs.com/blog/2024/11/embed-api-v2-deprecated/.
# fmt: off
is_disabled = (
# 12 hours brownout.
datetime.datetime(2024, 12, 9, 0, 0, 0, tzinfo=tzinfo) < now < datetime.datetime(2024, 12, 9, 12, 0, 0, tzinfo=tzinfo)
# 24 hours brownout.
or datetime.datetime(2025, 1, 13, 0, 0, 0, tzinfo=tzinfo) < now < datetime.datetime(2025, 1, 13, 0, 0, 0, tzinfo=tzinfo)
# Permanent removal.
or datetime.datetime(2025, 1, 20, 0, 0, 0, tzinfo=tzinfo) < now
)
# fmt: on
return is_disabled

def get(self, request):
"""Handle the get request."""

if self._is_disabled_for_deprecation():
return Response(
{
"error": (
"Embed API v2 has been deprecated and is no longer available, please use embed API v3 instead. "
"Read our blog post for more information: https://about.readthedocs.com/blog/2024/11/embed-api-v2-deprecated/."
)
},
status=status.HTTP_410_GONE,
)

project = self._get_project()
version = self._get_version()

Expand Down