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'}}
]

These are rough notes from whatever I was working on, interested in or thinking about at the time. They vary greatly in quality and length, but prove useful to me, and hopefully to you too!

← Previous: Kombu "timed out" bug: connection hangs forever in Kombu 4.1.0
Next: Avoid a process terminating when logging off a remote SSH session →