Skip to content

[background_tasks] No hook for a consumer module to register a beat schedule; docs imply one, and the commonly-cited on_after_configure signal doesn't fire under build_celery #199

Closed

Description

@antosubash

Summary

A consumer module can autodiscover tasks (ship tasks.py) but cannot register a periodic/beat schedule through any framework hook, and the obvious Celery approach is broken in this setup.

Environment

  • Framework checkout: v0.0.17-5-g2b079c9; smpy / published simple_module_* / @simple-module-py/*: 0.0.17
  • Python 3.12.3, uv 0.11.7, node v24.15.0, Linux (Ubuntu)

Found while building a real consumer app (Invoice Manager) on the framework.

Details

  • docs/modules/background_tasks.md implies make beat runs "beat schedules other modules add", but beat_schedule is a hardcoded dict in build_celery (celery_app.py) with the two internal tasks and no consumer registry/hook. No module adds entries.
  • The commonly-cited from celery.signals import on_after_configure does not work: on_after_configure is an app-instance signal (not a member of celery.signals → ImportError), and build_celery calls conf.update(...) (which fires it) before autodiscover_tasks(...) imports the module's tasks.py — so even connecting to the right object misses the already-fired signal.

Working pattern (used as the workaround)

In the module's tasks.py:

from celery import current_app, shared_task
from celery.schedules import crontab

@shared_task(name="invoices.generate_recurring")
def generate_recurring() -> int: ...

@current_app.on_after_finalize.connect
def _register(sender, **kw):
    sender.add_periodic_task(crontab(hour=6, minute=0), generate_recurring.s(),
                             name="invoices-generate-recurring-daily")

Verified: the entry lands in beat_schedule (0 6 * * *) alongside the built-ins.

Impact

Recurring features need this. Suggest either a first-class "register periodic task" hook for modules, or documenting the on_after_finalize pattern in background_tasks.md (and not on_after_configure).

Activity

  1. added a commit that references this issue on Jun 8, 2026
  2. antosubash commented on Jun 16, 2026

    @antosubash
    OwnerAuthor

    Resolved in #209 (released in v0.0.19) — modules register periodic work via a module-level BEAT_SCHEDULE dict in tasks.py, merged in build_celery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions