Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add celery config to the docs #428

Open
plumber-craic opened this issue Feb 13, 2022 · 0 comments
Open

Add celery config to the docs #428

plumber-craic opened this issue Feb 13, 2022 · 0 comments

Comments

@plumber-craic
Copy link

plumber-craic commented Feb 13, 2022

Feature Request

Please help us help you by filling out any applicable information in this template and removing the rest!

Is your feature request related to a problem?

Request to add some info to the docs

Describe the solution you'd like

A section for django-celery-beat periodic tasks

Additional context

Since the docs mention that additional integration examples would be welcome, and I don't know how to make a proper PR:

django-celery-beat

myapp/management/my_custom_command.py (can be called on app startup)

from django.core.management.base import BaseCommand, CommandError
from django_celery_beat.models import CrontabSchedule, PeriodicTask
import pytz


class Command(BaseCommand):
    help = 'Creates crontab schedule objects and periodic tasks that use them'

    def handle(self, *args, **options):
        every_day, _ = CrontabSchedule.objects.get_or_create(
            minute='0',
            hour='0',
            day_of_week='*',
            day_of_month='*',
            month_of_year='*',
            timezone=pytz.timezone('UTC')
        )

        PeriodicTask.objects.get_or_create(
            crontab=every_day,
            name='Backup DB',
            task='myapp.tasks.backup_db',
        )

        PeriodicTask.objects.get_or_create(
            crontab=every_day,
            name='Backup Media',
            task='myapp.tasks.backup_media',
        )

tasks.py

from celery import Celery
from django.core import management

app = Celery()


@app.task
def backup_db():
    management.call_command('dbbackup')


@app.task
def backup_media():
    management.call_command('mediabackup')

PR link

If you have opened a pull request to address the issue, please link it here.

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

No branches or pull requests

1 participant