42👍
Here is the gist of the idea:
On Machine A:
- Install Celery & RabbitMQ.
- Configure rabbitmq so that Machine B can connect to it.
- Create my_tasks.py with some tasks and put some tasks in queue.
On Machine B:
- Install Celery.
- Copy my_tasks.py file from machine A to this machine.
- Run a worker to consume the tasks
I had the same requirement and experimented with celery. It is a lot easier to do that. I wrote a detailed blog post on that few days back. Check out how to send tasks to remote machine?
14👍
You can make use of app.send_task()
with something like the following in your django project:
from celery import Celery
import my_client_config_module
app = Celery()
app.config_from_object(my_client_config_module)
app.send_task('dotted.path.to.function.on.remote.server.relative.to.worker',
args=(1, 2))
- [Django]-How to redirect with post data (Django)
- [Django]-RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS
- [Django]-Prevent django admin from escaping html
2👍
First, think about how celery really work?
Celery producer adds a task to queue with name and other important headers to identify the location of your task.
Celery does not add a complete executable function to MQ.
So, When you look at worker(consumer) side.
Celery gets task details from MQ and tries to run this.
To run this task there should be available module/files/environment/codebase to execute this task.
Now lets come to your question …
You try to set worker on a separate machine so logically to execute a function pointed by the task you need complete code environment of tasks and you should connect(Otherwise how you gonna get tasks from MQ ?) with your MQ where tasks live.
- [Django]-Best way to write an image to a Django HttpResponse()
- [Django]-Full text search: Whoosh Vs SOLR
- [Django]-Upload image available at public URL to S3 using boto
1👍
basically I will take ChillarAnand’s answer. I would like to add comment on his answer, but I can’t cause I don’t have 50 reputation.
so…
the answer to your question…
First you would like to read “how to send tasks to remote machine?”, as
ChillarAnand mentioned.
That is really good article, with one small flaw, such as “does not have ‘@app.task’ on the function def add(), in the content remote.py”, it caused problem and confused me as a newbie to celery.
And the answer to “[Errno 113] No route to host.” part,
I guess… I guess you have a firewall running in your rabbitmq server,
you might want to have a check. Most of time, it is iptables, but it could something else. Switch it off, or change the rules. Then you can give it another try.
- [Django]-Modulus % in Django template
- [Django]-How do I restart celery workers gracefully?
- [Django]-How to avoid AppConfig.ready() method running twice in Django