Sam Hooke

Celery pinging

In Celery, you can ping all workers with either app.control.ping() or app.control.inspect().ping(). The former has an optional timeout keyword argument, while the latter does not. Under the hood, the latter simply calls the former, but returns a slightly different data structure.

To compare:

>>> app.control.ping()
[
  {u'worker-one@hostname-a': {u'ok': u'pong'}},
  {u'worker-one@hostname-b': {u'ok': u'pong'}},
  {u'worker-one@hostname-c': {u'ok': u'pong'}},
  {u'worker-one@hostname-d': {u'ok': u'pong'}},
  {u'worker-two@hostname-b': {u'ok': u'pong'}},
  {u'worker-two@hostname-c': {u'ok': u'pong'}},
  {u'worker-two@hostname-d': {u'ok': u'pong'}},
  {u'worker-two@hostname-a': {u'ok': u'pong'}}
]
>>> app.control.inspect().ping()
{
  u'worker-two@hostname-b': {u'ok': u'pong'},
  u'worker-two@hostname-c': {u'ok': u'pong'},
  u'worker-two@hostname-d': {u'ok': u'pong'},
  u'worker-one@hostname-b': {u'ok': u'pong'},
  u'worker-one@hostname-a': {u'ok': u'pong'},
  u'worker-two@hostname-a': {u'ok': u'pong'},
  u'worker-one@hostname-c': {u'ok': u'pong'},
  u'worker-one@hostname-d': {u'ok': u'pong'}
}

In addition to the timeout paramater, another advantage of app.control.ping() is that you can specify the destination worker:

>>> app.control.ping(destination=[u'worker-one@hostname-a'])
[
  {u'worker-one@hostname-a': {u'ok': u'pong'}}
]