Horilla CRM uses Celery for async tasks and Celery Beat for schedules. AppLauncher merges per-app beat entries at startup; APScheduler handles select in-process jobs.

This post is Part 26 of 28 in the Horilla CRM Technical Blog series.

What are background jobs in Horilla CRM?

Background jobs in Horilla CRM enable you to:

  • celery_schedules.py per app
  • AppLauncher._register_celery_schedule()
  • USE_ASYNC_AUTOMATIONS for workflows
  • Redis broker in production

Per-app beat schedules

Scheduled work is decentralized by app. An app can expose a celery_schedules.py module with HORILLA_BEAT_SCHEDULE; AppLauncher discovers and merges that mapping into the project’s CELERY_BEAT_SCHEDULE during startup. This avoids one monolithic settings file while retaining a single Celery Beat instance that emits periodic jobs. Schedule keys should be stable and globally distinct, because duplicate keys from different apps can overwrite one another in the merged mapping.

The current app schedule sources include core export jobs, scheduled mail work in the mail app, activity meeting reminders, automations, workflow processing, and lead mail-to-lead processing. Add a schedule at the owning app rather than placing unrelated domain behavior in horilla.horilla_celery. For example, an activity reminder belongs beside activity tasks and scheduling definitions, where its model and tenant filtering rules can be maintained together.

from celery.schedules import crontab
HORILLA_BEAT_SCHEDULE = {
    "example-prune-expired-work": {
        "task": "horilla.contrib.example.tasks.prune_expired_work",
        "schedule": crontab(hour=2, minute=0),
    },
}

The example is a pattern, not an instruction to create a second beat process. Run one Beat scheduler for a logical deployment, or use a coordination mechanism when highly available scheduling is required; otherwise duplicate schedulers enqueue duplicate reminders and mails.

Automation execution mode

The automations signal handlers consult USE_ASYNC_AUTOMATIONS. When enabled, they dispatch automation processing asynchronously instead of completing all work in the model-save request. This is appropriate where automations can send email, produce notifications, or evaluate costly condition sets. It changes failure behavior: the save can succeed before downstream work is complete, so observability must cover both the request and worker sides. Administrators need a way to see failed tasks or automation run logs rather than assuming a successful form response proves delivery.

USE_ASYNC_AUTOMATIONS=True
CELERY_BROKER_URL=redis://redis:6379/0

Before enabling it, ensure workers run in every environment that accepts writes. Otherwise, automation requests are queued indefinitely. When disabled, still avoid long or unreliable provider calls in the transaction path; synchronous is not a replacement for reliable error handling.

APScheduler exception in mail

Celery is not the only scheduler in the project. The mail app uses APScheduler for Outlook token-related jobs. That in-process scheduler serves its specific lifecycle need, but it must not be casually duplicated across every web worker: multiple application processes can independently schedule the same refresh action. Know which process owns APScheduler and how it is started in the chosen deployment.

A complete production topology therefore normally has web/ASGI processes, Redis, one or more Celery workers, Celery Beat, the approved APScheduler owner where needed, and the database. Validate task import paths at worker startup, inspect the merged beat schedule, and exercise a safe scheduled task before relying on recurring mail or reminders. This architecture keeps each app responsible for its own schedule while horilla.horilla_celery, Redis, and the worker fleet provide the shared execution platform.

Benefits of Celery in Horilla CRM

  • Heavy import/export off the request cycle
  • Scheduled automations and exports
  • Scalable worker pools

Define beat schedules in your app’s celery_schedules.py — AppLauncher merges them when Django starts.

Continue the series

Previous: Part 25 — The Ultimate Guide to Calendar Integration in Horilla CRM

Next: Part 27 — How to Use Audit History and Recycle Bin in Horilla CRM

More posts are on the Horilla Blogs; share feedback on GitHub.

Share this article