How to configure Celery to send email alerts when tasks fail?
Asked Answered
M

2

12

How is it possible to configure celery to send email alerts when tasks are failing?

For example I want Celery to notify me when more than 3 tasks fail or more than 10 tasks are being retried.

Is it possible using celery or a utility (e.g. flower) or I have to write my own plugin?

Milanmilanese answered 7/7, 2014 at 11:46 Comment(0)
C
8

Yes, all you need to do is set CELERY_SEND_TASK_ERROR_EMAILS = True and if Celery process fails django will send message with traceback to all emails set in ADMINS settings.

Coronation answered 7/7, 2014 at 20:23 Comment(5)
Yes, thanks. but it has a problem that it sends an email for every failed task.Milanmilanese
Also is has nothing to do with Django, it will work even if you don't use Celery with Django as long as all the right config entries are there.Nystatin
The question was about getting alerts when a threshold of failed or retried tasks is reached, not sending an email for every task (could be thousands). See this answer to get list of failed tasks, from which you could calculate stats to send an alert.Pectinate
Is this option available for celery 4.x? I couldn't find such.Onassis
Not available anymore in version 4.xMorten
N
2

As far as I know, it's not possible out of the box.

You could write custom client on top of celery or flower or directly accessing RabbitMQ.

What I would do (and I am doing) is simply logging failed tasks and then use something like Graylog2 to monitor the log files, this works for all your infrastructure, not just Celery.

You can also use something like NewRelic which monitors your processes directly and offers many other features. Although email reporting on exceptions is somewhat limited in NewRelic.

A simple client/monitor probably is the quickest solution.

Nystatin answered 7/7, 2014 at 12:33 Comment(2)
So why the down vote? Read the question, the obvious answer is that you can't do that out of box. You can do what @Coronation said, but it's not serious. If something goes seriously wrong, you'll end up with 10k emails in your inbox.Nystatin
That downvote is my mistake. Your solution is ok, I haven't noticed that message should be send after X fails, not every fail. I can change my vote only when your answer will be edited.Coronation

© 2022 - 2024 — McMap. All rights reserved.