Search code examples
pythoncelery

Celery - How to send task from remote machine?


We have a server running celery workers and a Redis queue. The tasks are defined on that server.
I need to be able to call these tasks from a remote machine.
I know that it is done using send_task but I still haven't figured out HOW? How do I tell send_task where the queue is? Where do I pass connection params (or whatever needed)? I've been looking for hours and all I can find is this:

from celery.execute import send_task
send_task('tasks.add')

Well, that means that I need celery on my calling machine as well. But what else do I need to set up?


Solution

  • This may be a way: Creating a Celery object and using send_task from that object, the object can have the configuration to find the broker.

    from celery import Celery
    celery = Celery()
    celery.config_from_object('celeryconfig')
    celery.send_task('tasks.add', (2,2))
    

    celeryconfig is a file containing the celery configuration, there are other ways set config on the celery object.