Skip to content

Feat: Add celery beat for scheduling new cronjobs - #2813

Draft
susilnem wants to merge 4 commits into
project/spark-integrationfrom
feature/setup-celery-beat
Draft

Feat: Add celery beat for scheduling new cronjobs#2813
susilnem wants to merge 4 commits into
project/spark-integrationfrom
feature/setup-celery-beat

Conversation

@susilnem

Copy link
Copy Markdown
Member

Description

Introduce django-celery-beat so new cronjobs can be declared in code and
dispatched by a beat process, instead of adding another Kubernetes CronJob.

Existing cronjobs are untouched. The 30 legacy jobs keep running as k8s
CronJobs from values.yaml:cronjobs and stay monitored via SentryMonitor +
manage.py cron_job_monitor. A job belongs to one mechanism or the other,
never both -- SentryMonitor.validate_config() asserts the enum matches
values.yaml.

Changes

  • Introduce django-celery-beat
  • main/cronjobs.py: SCHEDULES registry, kombu queues (default/heavy/cronjob) feeding task_queues, per-job Sentry monitor config, and a beat_init hook that prunes PeriodicTask rows for removed jobs ("manual:" rows spared)
  • seed jobs: clear_expired_django_sessions (django_session was never pruned) and a per-queue celery_queue_uptime_check heartbeat
  • main/sentry.py: SentryConfig dataclass, every option passed to sentry_sdk.init() by name so an unrecognised key cannot reach it
  • SENTRY_DEBUG decouples Sentry verbosity from DJANGO_DEBUG
  • misc/dev: worker and beat entrypoints with a broker wait
  • tests in main/test_cronjobs.py, a django check for SCHEDULES task paths, and docs/cronjobs.md

Checklist

Things that should succeed before merging.

  • Updated/ran unit tests
  • Updated CHANGELOG.md

Release

If there is a version update, make sure to tag the repository with the latest version.

@thenav56 thenav56 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Comment thread api/tasks.py Outdated
Comment thread docker-compose.yml
Comment thread docker-compose.yml
- Introduce django-celery-beat
- main/cronjobs.py: SCHEDULES registry, kombu queues (default/heavy/cronjob)
  feeding task_queues, per-job Sentry monitor config, and a beat_init hook
  that prunes PeriodicTask rows for removed jobs ("manual:" rows spared)
- seed jobs: clear_expired_django_sessions (django_session was never pruned)
  and a per-queue celery_queue_uptime_check heartbeat
- main/sentry.py: SentryConfig dataclass, every option passed to
  sentry_sdk.init() by name so an unrecognised key cannot reach it
- SENTRY_DEBUG decouples Sentry verbosity from DJANGO_DEBUG
- misc/dev: worker and beat entrypoints with a broker wait
- tests in main/test_cronjobs.py, a django check for SCHEDULES task paths,
  and docs/cronjobs.md
The banjo stack passes traces_sampler= to SENTRY_CONFIG, but the SentryConfig
dataclass only had traces_sample_rate, so settings import raised
TypeError: unexpected keyword argument 'traces_sampler' in every process where
SENTRY_DSN is set.

Keep the rate on the dataclass and build banjo's health-probe-ignoring sampler
inside init_sentry(), so the config stays plain data and dataclasses.replace()
does not carry a closure.
Adds app.worker.addons.beat so the cronjobs in main/cronjobs.py actually run in
deployed environments; previously beat existed only in docker-compose.

- replicaCount: 1 with strategy: Recreate -- two beat processes would fire
  every cronjob twice
- --scheduler=banjo_utils.celery_health.database.HeartbeatDatabaseScheduler so
  banjo-celery-probe can check liveness
- SENTRY_DEBUG and SENTRY_MONITOR_CELERY_BEAT_TASKS added to app.env
- snapshots regenerated for alpha/staging/production
@susilnem
susilnem force-pushed the feature/setup-celery-beat branch from ea93c8e to b443e33 Compare September 9, 2026 06:41
@susilnem
susilnem changed the base branch from project/spark-integration to develop September 9, 2026 06:46
@susilnem
susilnem changed the base branch from develop to project/spark-integration September 9, 2026 06:46
@susilnem
susilnem force-pushed the feature/setup-celery-beat branch from b443e33 to 9948ab4 Compare September 9, 2026 09:08
Replaces misc/wait-for-broker.sh with banjo's
`manage.py wait_for_resources --db --celery-broker`, which also waits for the
database instead of only the broker.
@susilnem
susilnem force-pushed the feature/setup-celery-beat branch from 9948ab4 to 522af1f Compare September 9, 2026 09:51
@susilnem susilnem changed the title WIP: Feat: Add celery beat for scheduling new cronjobs Feat: Add celery beat for scheduling new cronjobs Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants