Register Custom Domain
Celery tasks for registering llmclient custom domains.
This module defines Celery tasks for registering custom domains for llmclients, including creating DNS zones, TLS certificates, and DNS records in the cloud provider, as well as associating domains with accounts.
Main Tasks
- register_custom_domain(account_id, domain_name):
Registers a customer’s custom domain name in the cloud provider’s DNS and associates its zone with the account.
Signals
pre_register_custom_domain: Sent before custom domain registration begins.
post_register_custom_domain: Sent after custom domain registration is completed.
Configuration
Celery task behavior (retries, backoff, queue) is controlled by smarter_settings.
Logging
Task execution and domain registration are logged using the smarter logging library, with waffle switches for task and llmclient logging.
Usage
Import this module and call the Celery task as needed to asynchronously register an llmclient custom domain:
register_custom_domain.delay(account_id, domain_name)
- raises LLMClientCustomDomainExists:
If the domain is already registered to another account.
- raises Exception:
Any exception during task execution will trigger a retry according to Celery settings.
- smarter.apps.llmclient.tasks.register_custom_domain.already_registered(account, account_id, domain_name, task_id)[source]
Whether the account’s custom domain exists, and its certificate is issued, so there is nothing to register.
If so, its verification is queued, unless it is verified, and post_register_custom_domain is sent. If not, why is logged, and the registration proceeds.
- smarter.apps.llmclient.tasks.register_custom_domain.create_validation_records(certificate_id, account_id, domain_name, attempt, task_id)[source]
Create, or find, a certificate’s DNS validation records, with one look, or queue the task to look again.
- Parameters:
- Return type:
- Returns:
True if the records exist, False if the task was queued again.
- Raises:
CertificateNotFound – If the certificate still doesn’t exist after the last attempt.
CertificateTimeout – If its records are still not generated after the last attempt.
DNSRecordTimeout – If a record is still not in the zone after the last attempt.
- smarter.apps.llmclient.tasks.register_custom_domain.requeue_countdown(error)[source]
Seconds until the next look, after a wait that isn’t over: the interval of the service that waits.
- smarter.apps.llmclient.tasks.register_custom_domain.register_custom_domain(account_id, domain_name, attempt=1)
Register a customer’s custom domain name in the cloud provider’s DNS and associate its zone with the account.
This Celery task performs the following steps: 1. Sends a pre-register signal for the custom domain. 2. Checks if the custom domain and certificate already exist and are verified. 3. Ensures the domain is not registered by another account. 4. Creates a DNS zone for the custom domain if needed. 5. Associates the DNS zone with the account. 6. Creates or retrieves a TLS certificate for the domain. 7. Creates a DNS record for the certificate and triggers verification. 8. Sends a post-register signal for the custom domain.
- Parameters:
account_id (
int) – The primary key of the Account for which the custom domain is being registered.domain_name (
str) – The custom domain name to register.attempt (
int) – The number of this run. A new certificate’s validation records take a few seconds to be generated, and a new DNS record to appear in its zone: rather than sleep (ADR-030, rule 2), the task looks once, and queues itself again, up to the certificate service’svalidation_wait_attemptsruns.Signals
-------
pre_register_custom_domain (django.dispatch.Signal) – Sent before the custom domain registration begins.
post_register_custom_domain (django.dispatch.Signal) – Sent after the custom domain registration is completed.
- Returns:
True if the domain is registered, or already was, False if the infrastructure services are not available, so nothing was done, and None if it will look again.
- Return type:
- Raises:
LLMClientCustomDomainExists – If the domain is already registered to another account.
Exception – Any exception raised during the registration process will trigger a retry according to Celery settings.