celery

Celery: Spawn "sidecar" webserver process

Celery: Spawn "sidecar" webserver process Question: I’m trying to collect metrics from my Celery workers, which seemed simply enough, but turns out to be utterly, ridiculously hard. After lots of approaches, I’m now trying to spawn an additional process next to the Celery worker/supervisor that hosts a simple HTTP server to expose Prometheus metrics. To …

Total answers: 2

Setup an email notification when consumer: Connection to broker lost in celery

Setup an email notification when consumer: Connection to broker lost in celery Question: I want to implement an email system which will send an email whenever my celery worker lost connection with my Redis server. Whenever it lost connection it gives warning: [2023-03-02 21:33:48,272: WARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection… …

Total answers: 1

flask getting celery AsyncResult task via id returns incorrect task

flask getting celery AsyncResult task via id returns incorrect task Question: I’m trying to get celery running with flask and then show the result, according to this tutorial: https://blog.miguelgrinberg.com/post/using-celery-with-flask. But after the task successfully finished, the flask app still sees a "pending" task. The way of grabbing the task via id apparently does not return …

Total answers: 1

Can we get the signature or arguments of a celery task on `task_prerun`

Can we get the signature or arguments of a celery task on `task_prerun` Question: My plan is to log all celery task requests with the arguments they receive s I’m using the following @task_prerun.connect() def log_celery_args(task, **kwargs): logger.info(f"{task.name} {kwargs[‘kwargs’]}", extra=kwargs[‘kwargs’]) The problem is this solution doesn’t work when the functions don’t use named parameters. I …

Total answers: 1

How create task with celery in django? POO issue?

How create task with celery in django? POO issue? Question: I’m trying to set up a task with Django and Celery. The Celery and Django configuration is okay, nothing to report on that side. However, I have a problem, I think with the writing, of my code in OOP. I can’t locate where the problem …

Total answers: 1

Release redis lock if process die

Release redis lock if process die Question: I’m using redis distributed locks to make sure some celery tasks don’t run concurrently. For managing locks with redis I’m using the python redis library version 4.0.0 (which specifies that any deadlock problems should be handled by the programmer). Since I would like to avoid using the timeout …

Total answers: 1

Send tasks to a Celery app on a remote server

Send tasks to a Celery app on a remote server Question: I have a server (Ubuntu Server) on the local network on ip address: 192.168.1.9. This server is running RabbitMQ in docker. I defined a basic Celery app: from celery import Celery app = Celery( ‘tasks’, brocker=’pyamqp://<username>:<password>@localhost//’, backend=’rpc://’, ) @app.task def add(x, y): return x …

Total answers: 2

Execute statement only once in Python

Execute statement only once in Python Question: I’m running a periodic task on Celery that executes the same code once every 3 minutes. If a condition is True, an action is performed (a message is sent), but I need that message to be sent only once. The ideal would be that that message, if sent, …

Total answers: 2

Patch Django EmailMultiAlternatives send() in a Celery Task so that an exception is raised

Patch Django EmailMultiAlternatives send() in a Celery Task so that an exception is raised Question: I want to test a Celery Task by raising an SMTPException when sending an email. With the following code, located in: my_app.mailer.tasks from django.core.mail import EmailMultiAlternatives @app.task(bind=True ) def send_mail(self): subject, from_email, to = ‘hello’, ‘[email protected]’, ‘[email protected]’ text_content = ‘This …

Total answers: 2

What's the difference between FastAPI background tasks and Celery tasks?

What's the difference between FastAPI background tasks and Celery tasks? Question: Recently I read something about this and the point was that celery is more productive. Now, I can’t find detailed information about the difference between these two and what should be the best way to use them. Asked By: Maksim Burtsev || Source Answers: …

Total answers: 1