Skip to content

Commit 29f31de

Browse files
committed
Fixes
1 parent 9a5b58b commit 29f31de

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

readthedocs/api/v2/models.py

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

3+
from django.conf import settings
34
from django.db import models
45
from django.utils import timezone
56
from django.utils.translation import gettext_lazy as _

readthedocs/settings/base.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,33 @@ def TEMPLATES(self):
589589
USE_I18N = True
590590
USE_L10N = True
591591

592+
BUILD_TIME_LIMIT = 900 # seconds
593+
594+
@property
595+
def BUILD_MEMORY_LIMIT(self):
596+
"""
597+
Set build memory limit dynamically, if in production, based on system memory.
598+
599+
We do this to avoid having separate build images. This assumes 1 build
600+
process per server, which will be allowed to consume all available
601+
memory.
602+
"""
603+
# Our normal default
604+
default_memory_limit = "7g"
605+
606+
# Only run on our servers
607+
if self.RTD_IS_PRODUCTION:
608+
total_memory, memory_limit = self._get_build_memory_limit()
609+
610+
memory_limit = memory_limit or default_memory_limit
611+
log.info(
612+
"Using dynamic build limits.",
613+
hostname=socket.gethostname(),
614+
memory=memory_limit,
615+
)
616+
return memory_limit
617+
618+
592619
# Celery
593620
CELERY_APP_NAME = "readthedocs"
594621
CELERY_ALWAYS_EAGER = True
@@ -605,7 +632,7 @@ def TEMPLATES(self):
605632
# https://github.com/readthedocs/readthedocs.org/issues/12317#issuecomment-3070950434
606633
# https://docs.celeryq.dev/en/stable/getting-started/backends-and-brokers/redis.html#visibility-timeout
607634
BROKER_TRANSPORT_OPTIONS = {
608-
'visibility_timeout': self.BUILD_TIME_LIMIT * 1.15, # 15% more than the build time limit
635+
'visibility_timeout': BUILD_TIME_LIMIT * 1.15, # 15% more than the build time limit
609636
}
610637

611638
CELERY_DEFAULT_QUEUE = "celery"
@@ -741,32 +768,6 @@ def _get_build_memory_limit(self):
741768
# int and raise a ValueError
742769
log.exception("Failed to get memory size, using defaults Docker limits.")
743770

744-
BUILD_TIME_LIMIT = 900 # seconds
745-
746-
@property
747-
def BUILD_MEMORY_LIMIT(self):
748-
"""
749-
Set build memory limit dynamically, if in production, based on system memory.
750-
751-
We do this to avoid having separate build images. This assumes 1 build
752-
process per server, which will be allowed to consume all available
753-
memory.
754-
"""
755-
# Our normal default
756-
default_memory_limit = "7g"
757-
758-
# Only run on our servers
759-
if self.RTD_IS_PRODUCTION:
760-
total_memory, memory_limit = self._get_build_memory_limit()
761-
762-
memory_limit = memory_limit or default_memory_limit
763-
log.info(
764-
"Using dynamic build limits.",
765-
hostname=socket.gethostname(),
766-
memory=memory_limit,
767-
)
768-
return memory_limit
769-
770771
# Allauth
771772
ACCOUNT_ADAPTER = "readthedocs.core.adapters.AccountAdapter"
772773
SOCIALACCOUNT_ADAPTER = 'readthedocs.core.adapters.SocialAccountAdapter'

0 commit comments

Comments
 (0)