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.

Parameters:
  • account (Account) – The account.

  • account_id (int) – Its id, for the signal.

  • domain_name (str) – The resolved domain name.

  • task_id (str | None) – The task’s id, for logging and the signal.

Return type:

bool

Returns:

True if the domain is already registered.

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:
  • certificate_id (str) – The provider’s id of the certificate.

  • account_id (int) – The task’s account, to queue it again.

  • domain_name (str) – The task’s domain, to queue it again.

  • attempt (int) – The number of this run of the task.

  • task_id (str | None) – The task’s id, for logging.

Return type:

bool

Returns:

True if the records exist, False if the task was queued again.

Raises:
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.

Parameters:

error (Exception) – The wait’s error: a DNS record that hasn’t appeared, or a certificate, or its validation records, that don’t exist yet.

Return type:

float

Returns:

The DNS service’s record_wait_seconds, or the certificate service’s validation_wait_seconds.

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’s validation_wait_attempts runs.

  • 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:

bool | None

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.