• 15

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

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

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

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.send_task('tasks.add', (2,2))

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

  • 46
Reply Report
      • 2
    • OK, that's great man... now a real test. How do you utilize a callback with that so I can get the actual value returned from the task??
      • 2
    • Something that threw me off for a few hours was that I needed to define which queue my producing script was putting the 'jobs'. ended up with celery.send_task('tasks.the_remote_task_name', ([arguments,...]), queue='name_of_queue') got from this link
      • 1
    • I recently had a similar problem where by the send_task invocation was correct, however the task was not found by the server. I was receiving an error "Received unregistered task of type... ". To solve this, in your tasks definitions decorator add the 'name' argument. Example can be found here

There are several ways to define routing rules, the most general of which is the custom router object. In all cases, the caller just provides a routing_key parameter in send_task, delay or apply_async and the router determines which queue to send the task into.

  • 0
Reply Report
      • 2
    • Thanks, but this leads me back to the start. Where do I define this route key? Do I need a config file on the calling machine? Or is there something else I need to configure before calling send_task?
      • 1
    • The doc you mentioned doesn't explain how to tell send_task to use redis. It only explains how to setup the worker. By doing that, send_task returns "Connection refused" error(at least for me)

on the remote machine, start up celery with the broker_url pointing to the machine you want to run the tasks on. Then just submit the tasks (if you have specific queues to submit to, then add the appropriate routing keys).

  • 0
Reply Report

Trending Tags