L
L
Leo2015-02-18 19:34:28
Django
Leo, 2015-02-18 19:34:28

Can Celery write the result to a database on another host?

The situation is this. There is a server ( server1 ) with django , mysql subd and Celery (+django-celery). Also, several workers are running on this server.
One task ( task0 ) starts according to the schedule, makes a request via django orm, receives data, splits it into separate parts and sends it for processing ( task2 ) to other workers using the rabbitmq broker . They receive data from the queue, perform certain manipulations with the data, and save the results-objects in the database. Everything works great
on one server , the question is the following. server2
If I need to install the workers on another machine ( ), then they will essentially need access to the database that is on server1 .
Do I understand correctly that it will be necessary to clone the entire project on server2 , change the db connection day IP in settings.py , and start the workers? It all looks not very tempting, maybe there is some other way?
Read this :

If you want to store task results in the Django database then you still need to install the django-celery library for that (alternatively you can use the SQLAlchemy result backend).

I tried to run the workers locally, but the results of the tasks did not appear anywhere in the database.
CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler',

So far, there is no urgent task in moving workers to another server, but I'm interested in the future.
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Kuzmichev, 2015-02-18
@Assargin

I myself recently deployed Celery. So far, too, everything is spinning on one server.

  1. Your database that your django project works with and your celery result backend are two different things. The latter is, roughly speaking, a store for values ​​that you can return from a pending task. And the project database is the project database, although it can also perform the function of the result backend. By the way, you may not use the result backend at all, unless you need to return something from the tasks.
  2. Your django project's worker processes and celery workers are the same, just run through different entry points. For the web, this is most likely wsgi.py, for celery, for example, celery.py.
  3. In order to run workers on server 2 (instead of or in addition to server 1), you will need to deploy your project on it, and do the same thing as on server 1 to get celery workers working.
  4. in addition to connecting to the database, you will also need to take care of connecting to the broker and the result backend (if you use it). In the simplest case, as I see it, no IP will need to be changed - why, if you have one database server and is located on the 1st server. Well, except that instead of 127.0.0.1 you will need to register a normal address.

R
Ruslan Luxurious, 2015-02-19
@oshikuru

Everything will work great. Ideally, also put the database on a separate machine. And connect to it both from one server and from another.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question