Ejemplo n.º 1
0
def map_task_per_tenants(task: Task, sequential: bool = False) -> None:
    # todo: filtering by tenant status
    tenants_ids = list(
        TenantModel.objects.exclude(
            schema_name=public_schema_name).values_list('id', flat=True))
    if sequential:
        logger.info("Submitting tasks for tenants: %s" %
                    str(task.map(tenants_ids).apply_async()))
    else:
        logger.info("Submitting tasks for tenants: %s" % ', '.join(
            [str(task.delay(tenant_id)) for tenant_id in tenants_ids]))
Ejemplo n.º 2
0
def schedule(force=False):
    for site in Site.objects.all():
        if site.needs_check:
            Task.delay(check, site.id)
def run_task_on_commit(task: Task, args: Iterable = [], kwargs: Mapping = {}):
    """Run a celery task after the next database commit (if we are in a transaction)"""
    transaction.on_commit(lambda: task.delay(*args, **kwargs))