Skip to content

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

Draft
susilnem wants to merge 1 commit into
project/spark-integrationfrom
feature/setup-celery-beat
Draft

WIP: Feat: Add celery beat for scheduling new cronjobs#2813
susilnem wants to merge 1 commit 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.

- 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

@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
logger.info(f"End export: {export.pk}")


# TODO(susilnem): Do we need this cron?

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But it would be effective only for the admin panel users. right?

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.

Yes sir

Comment thread docker-compose.yml
command: python manage.py run_celery_dev
restart: unless-stopped
command: ./misc/dev/run_worker.sh
healthcheck:

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.

Let's add TODO here for healthcheck to upate after banjo-utils integration

Comment thread docker-compose.yml
celery-beat:
<<: *base_server_setup
restart: unless-stopped
command: ./misc/dev/run_worker_beat.sh

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.

Let's add TODO here for healthcheck to upate after banjo-utils integration

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