"""
The one place that queues the provider app's Celery tasks.
Every task of the app is queued by a function of this module, never by ``<task>.delay()`` or
``<task>.apply_async()`` anywhere else (ADR-030, rule 10, issue #1098). So this module is where to look for what
queues a task, and the one place that a test patches so that nothing reaches a real worker. Each function queues
its task once the current transaction commits, so that the worker finds the row it verifies.
"""
from django.db import transaction
from smarter.apps.provider.models import Provider, ProviderModel
from .verify import verify_provider, verify_provider_model
[docs]
def queue_verify_provider(provider: Provider) -> None:
"""
Queue :func:`~smarter.apps.provider.tasks.verify.verify_provider`, which runs a provider's test bank.
The ``provider_verification_requested`` receiver calls it, e.g. when :meth:`Provider.verify` is called.
:param provider: The Provider.
"""
provider_id = provider.pk
transaction.on_commit(lambda: verify_provider.delay(provider_id=provider_id))
[docs]
def queue_verify_provider_model(provider_model: ProviderModel) -> None:
"""
Queue :func:`~smarter.apps.provider.tasks.verify.verify_provider_model`, which runs a provider model's test bank.
The ``model_verification_requested`` receiver calls it, e.g. when a ProviderModel is created.
:param provider_model: The ProviderModel.
"""
provider_model_id = provider_model.pk
transaction.on_commit(lambda: verify_provider_model.delay(provider_model_id=provider_model_id))
__all__ = ["queue_verify_provider", "queue_verify_provider_model"]