Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery AsyncResult get hostname

I have a celery set up that uses two different servers to process tasks. I'm trying to figure out the best way to match which server the task completed on. I looked through the docs and didn't see anything about retrieving the hostname from an AsyncResult.

Any input on this matter is appreciated. Another option I was thinking of trying is simply putting the hostname within each celery config, although this method is not desired as it is one more thing to remember to do.

like image 270
user1595702 Avatar asked Dec 04 '12 16:12

user1595702


1 Answers

A possible workaround is returning the hostname with task return value

from celery import current_task

@celery.task
def hello(x, y):
  return dict(hostname=current_task.request.hostname, result='hello')
like image 194
mher Avatar answered Oct 06 '22 22:10

mher