1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

feat(operations): worker concurrency and job retention settings

This commit is contained in:
catborise 2026-10-13 18:12:54 +03:00
parent 18146c30a1
commit 34582d23f3
6 changed files with 94 additions and 1 deletions

View file

@ -0,0 +1,13 @@
from django.test import TestCase
from appsettings.models import AppSettings
from operations import utils
class ConfTestCase(TestCase):
def test_defaults_and_bounds(self):
self.assertEqual((utils.concurrency(), utils.retention_days()), (4, 30))
AppSettings.objects.filter(key="WORKER_CONCURRENCY").update(value="99")
self.assertEqual(utils.concurrency(), 4)
AppSettings.objects.filter(key="WORKER_CONCURRENCY").update(value="8")
self.assertEqual(utils.concurrency(), 8)

View file

@ -1,6 +1,8 @@
"""Secrets never reach a job record, a response or a log line. What a refused
request says about the job holding the resource: details for its owner and
superusers, a minimal summary for everyone else."""
superusers, a minimal summary for everyone else. Worker settings from the
Settings page. The worker reads them itself (the settings middleware only runs
in gunicorn)."""
import re
@ -8,6 +10,8 @@ from django.utils import timezone
from django.utils.timesince import timesince
from django.utils.translation import gettext as _
from appsettings.models import AppSettings
from . import jobs
_NAMES = r"(?:pass|secret|token|key)\w*"
@ -21,6 +25,8 @@ _PATTERNS = [
]
_SECRET_KEY = re.compile(r"pass|secret|token|private|key$", re.I)
BOUNDS = {"WORKER_CONCURRENCY": (1, 16, 4), "JOB_RETENTION_DAYS": (1, 3650, 30)}
def safe_text(text):
text = str(text)
@ -60,3 +66,20 @@ def busy_message(busy, user):
return _("%(label)s is %(state)s on this resource (started by %(user)s, %(since)s ago); "
"see the Jobs page.") % {**values, "user": op.username}
return _("%(label)s is %(state)s on this resource (since %(since)s).") % values
def _value(key):
low, high, default = BOUNDS[key]
try:
value = int(AppSettings.objects.get(key=key).value)
except (AppSettings.DoesNotExist, ValueError):
return default
return value if low <= value <= high else default
def concurrency():
return _value("WORKER_CONCURRENCY")
def retention_days():
return _value("JOB_RETENTION_DAYS")