Skip to content

Commit

Permalink
Fix #6844 by allowing safe (i.e. skip arg derserialization) queries v…
Browse files Browse the repository at this point in the history
…ia app.inspect().active().
  • Loading branch information
Damir Jungic committed Jul 8, 2021
1 parent e972aff commit f2d2f90
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
7 changes: 3 additions & 4 deletions celery/app/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,17 @@ def clock(self):

def active(self, safe=None):
"""Return list of tasks currently executed by workers.
Arguments:
safe (Boolean): Set to True to disable deserialization.
Returns:
Dict: Dictionary ``{HOSTNAME: [TASK_INFO,...]}``.
See Also:
For ``TASK_INFO`` details see :func:`query_task` return value.
Note:
``safe`` is ignored since 4.0 as no objects will need
serialization now that we have argsrepr/kwargsrepr.
"""
return self._request('active')
return self._request('active', safe=safe)

def scheduled(self, safe=None):
"""Return list of scheduled tasks with details.
Expand Down
4 changes: 2 additions & 2 deletions celery/worker/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ def reserved(state, **kwargs):


@inspect_command(alias='dump_active')
def active(state, **kwargs):
def active(state, safe=False, **kwargs):
"""List of tasks currently being executed."""
return [request.info()
return [request.info(safe=safe)
for request in state.tset(worker_state.active_requests)]


Expand Down
4 changes: 2 additions & 2 deletions celery/worker/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ def info(self, safe=False):
return {
'id': self.id,
'name': self.name,
'args': self._args,
'kwargs': self._kwargs,
'args': self._args if not safe else self._argsrepr,
'kwargs': self._kwargs if not safe else self._kwargsrepr,
'type': self._type,
'hostname': self._hostname,
'time_start': self.time_start,
Expand Down
4 changes: 4 additions & 0 deletions t/unit/app/test_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def test_active(self):
self.inspect.active()
self.assert_broadcast_called('active')

def test_active_safe(self):
self.inspect.active(safe=True)
self.assert_broadcast_called('active', safe=True)

def test_clock(self):
self.inspect.clock()
self.assert_broadcast_called('clock')
Expand Down
14 changes: 14 additions & 0 deletions t/unit/worker/test_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ def test_active(self):
finally:
worker_state.active_requests.discard(r)

def test_active_safe(self):
kwargsrepr = '<anything>'
r = Request(
self.TaskMessage(self.mytask.name, id='do re mi',
kwargsrepr=kwargsrepr),
app=self.app,
)
worker_state.active_requests.add(r)
try:
active_resp = self.panel.handle('dump_active', {'safe': True})
assert active_resp[0]['kwargs'] == kwargsrepr
finally:
worker_state.active_requests.discard(r)

def test_pool_grow(self):

class MockPool:
Expand Down

0 comments on commit f2d2f90

Please sign in to comment.