Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0dbc528d08 |
@@ -63,3 +63,15 @@ def fetch_domains_status_task(status: str):
|
||||
if old_status != domain.status:
|
||||
changed_domains.append(f"{domain.name} ({domain.status})")
|
||||
return changed_domains
|
||||
|
||||
|
||||
@celery_app.task
|
||||
def fetch_domain_status_task(zone_name: str):
|
||||
"""Celery task to call dimail to check and update a single domain's status."""
|
||||
client = DimailAPIClient()
|
||||
for domain in MailDomain.objects.filter(name=zone_name):
|
||||
logger.info("Checking status of domain %s", domain.name)
|
||||
try:
|
||||
client.fetch_domain_status(domain)
|
||||
except requests.exceptions.HTTPError as err:
|
||||
logger.error("Failed to fetch status for domain %s: %s", domain.name, err)
|
||||
|
||||
@@ -11,8 +11,9 @@ from requests.adapters import HTTPAdapter, Retry
|
||||
|
||||
from core.plugins.base import BaseOrganizationPlugin
|
||||
|
||||
from mailbox_manager.enums import MailDomainRoleChoices
|
||||
from mailbox_manager.enums import MailDomainRoleChoices, MailDomainStatusChoices
|
||||
from mailbox_manager.models import MailDomain, MailDomainAccess
|
||||
from mailbox_manager.tasks import fetch_domain_status_task
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -263,7 +264,13 @@ class CommuneCreation(BaseOrganizationPlugin):
|
||||
|
||||
zone_name = self.zone_name(name)
|
||||
support = "support-regie@numerique.gouv.fr"
|
||||
MailDomain.objects.get_or_create(name=zone_name, support_email=support)
|
||||
MailDomain.objects.get_or_create(
|
||||
name=zone_name,
|
||||
support_email=support,
|
||||
status=MailDomainStatusChoices.ENABLED,
|
||||
)
|
||||
|
||||
fetch_domain_status_task.apply_async(args=[zone_name], countdown=300)
|
||||
|
||||
# Compute and execute the rest of the process
|
||||
tasks = self.complete_commune_creation(name)
|
||||
|
||||
Reference in New Issue
Block a user