M
M
marselabdullin2020-07-08 14:37:11
Django
marselabdullin, 2020-07-08 14:37:11

Why doesn't celery send an email at the specified time?

I sent mail an hour before the event (model in django), checked the date check in the shell, but celery does not send mail or print to the console. There is a premonition that something has not been completed, since it has not worked with the planned actions yet. but no ideas. I didn’t include shedule.py anywhere, maybe this is the reason for

tasks.py:

@shared_task
def event_send_mail():
    events = Event.objects.filter(event_date=datetime.now() + timedelta(minutes=60))
    for event in events:
        print("Событие")
        send_mail("Напоминание о событии", str(event.title) + "начинаеся через час",
                                     "[email protected]", [event.user.email, ])


schedule.py:
CELERYBEAT_SCHEDULE = {
    'send_mail': {
        'task': 'send_mail',
        'schedule': timedelta(minutes=1),
    },
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2020-07-08
@pyHammer

celery is quite bulky for such simple tasks. I would advise you to use python rq. To complete your task, you will need to set up a Django environment inside the task to load the required models. Then just pick up cron. This is the simplest and helps to get rid of complicated celery

S
szelga, 2020-07-09
@szelga

check if you have started a separate process for celery-beats: https://docs.celeryproject.org/en/stable/userguide...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question