(domains) define domain check interval as a settings

For now, to avoid overloading dimail, we have defined a
time interval between each check request to dimail.
This interval should be configurable for testing and
different environments.
This commit is contained in:
Sabrina Demagny
2025-03-21 18:38:41 +01:00
parent 7dac39034a
commit feb5d7154b
4 changed files with 13 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ and this project adheres to
### Added
- ✨(domains) define domain check interval as a settings
- ✨(oidc) add simple introspection backend #832
- 🧑‍💻(tasks) run management commands #814

View File

@@ -2,6 +2,8 @@
import time
from django.conf import settings
import requests
from celery import Celery
from celery.schedules import crontab
@@ -54,7 +56,7 @@ def fetch_domains_status_task(status: str):
for domain in MailDomain.objects.filter(status=status):
old_status = domain.status
# wait 10 seconds between each domain treatment to avoid overloading dimail
time.sleep(10)
time.sleep(settings.MAIL_CHECK_DOMAIN_INTERVAL)
try:
client.fetch_domain_status(domain)
except requests.exceptions.HTTPError as err:

View File

@@ -5,6 +5,8 @@ Unit tests for mailbox manager tasks.
import json
import re
from django.test import override_settings
import pytest
import responses
@@ -15,6 +17,7 @@ from .fixtures.dimail import CHECK_DOMAIN_BROKEN_INTERNAL, CHECK_DOMAIN_OK
pytestmark = pytest.mark.django_db
@override_settings(MAIL_CHECK_DOMAIN_INTERVAL=0)
@responses.activate
def test_fetch_domain_status_task_success(): # pylint: disable=too-many-locals
"""Test fetch domain status from dimail task"""
@@ -78,6 +81,7 @@ def test_fetch_domain_status_task_success(): # pylint: disable=too-many-locals
assert domain_disabled.status == enums.MailDomainStatusChoices.DISABLED
@override_settings(MAIL_CHECK_DOMAIN_INTERVAL=0)
@responses.activate
def test_fetch_domains_status_error_handling(caplog):
"""Test fetch domain status from dimail task with error"""

View File

@@ -540,6 +540,11 @@ class Base(Configuration):
environ_name="MAIL_PROVISIONING_API_TIMEOUT",
environ_prefix=None,
)
MAIL_CHECK_DOMAIN_INTERVAL = values.IntegerValue(
default=10,
environ_name="MAIL_CHECK_DOMAIN_INTERVAL",
environ_prefix=None,
)
DNS_PROVISIONING_API_URL = values.Value(
default="https://api.scaleway.com",
environ_name="DNS_PROVISIONING_API_URL",