Skip to content

Commit 82320aa

Browse files
authored
Build: use 24h for build API token expiry date (#12469)
We are still hitting issues with expired tokens. This commit increases the expiry date to 24hs as an initial test to try to mitigate this issue and have more data about the surrounding problems. Closes #12467
1 parent 714073d commit 82320aa

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

readthedocs/api/v2/models.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from datetime import timedelta
22

3-
from django.conf import settings
43
from django.db import models
54
from django.utils import timezone
65
from django.utils.translation import gettext_lazy as _
@@ -24,9 +23,17 @@ def create_key(self, project):
2423
2524
and can be revoked at any time by hitting the /api/v2/revoke/ endpoint.
2625
"""
27-
delta = (
28-
project.container_time_limit or settings.BUILD_TIME_LIMIT
29-
) * 1.25 + settings.RTD_BUILDS_RETRY_DELAY * settings.RTD_BUILDS_MAX_RETRIES
26+
# delta = (
27+
# project.container_time_limit or settings.BUILD_TIME_LIMIT
28+
# ) * 1.25 + settings.RTD_BUILDS_RETRY_DELAY * settings.RTD_BUILDS_MAX_RETRIES
29+
#
30+
# Use 24 hours for now since we are hitting the expiry date and we shouldn't
31+
# https://github.com/readthedocs/readthedocs.org/issues/12467
32+
#
33+
# NOTE: this is the maximum time this token will be valid, since the
34+
# default behavior is to revoke from the builder itself when the build
35+
# at `after_return` immediately before the build finishes
36+
delta = 60 * 60 * 24 # 24h
3037
expiry_date = timezone.now() + timedelta(seconds=delta)
3138
name_max_length = self.model._meta.get_field("name").max_length
3239
return super().create_key(

readthedocs/rtd_tests/tests/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,14 +814,14 @@ def test_expiricy_key(self):
814814
project = get(Project)
815815
build_api_key_obj, build_api_key = BuildAPIKey.objects.create_key(project)
816816
expected = (build_api_key_obj.expiry_date - timezone.now()).seconds
817-
self.assertAlmostEqual(expected, 8250, delta=5)
817+
self.assertAlmostEqual(expected, 86400, delta=5)
818818

819819
# Project with a custom containe time limit
820820
project.container_time_limit = 1200
821821
project.save()
822822
build_api_key_obj, build_api_key = BuildAPIKey.objects.create_key(project)
823823
expected = (build_api_key_obj.expiry_date - timezone.now()).seconds
824-
self.assertAlmostEqual(expected, 9000, delta=5)
824+
self.assertAlmostEqual(expected, 86400, delta=5)
825825

826826
def test_user_doesnt_get_full_api_return(self):
827827
user_normal = get(User, is_staff=False)

0 commit comments

Comments
 (0)