django get all running/pending celery task for current django user -
is there pythonic way running/pending celery tasks current loggedin django user? pseudo code trying:
@celery.task def process_task(user, task_to_do): #get running or pending(queued) task current user user_tasks = user.get_task(status=pending or status=started) if not user_task: #allow user schedule additional task process.... else: return "your previous tasks running"
that's in general tricky task.
first need implement inspecting of workers
inspector = app.control.inspect() scheduled = inspector.scheduled() reserved = inspector.reserved() active = inspector.active()
celery them broker. point - broker not store information user, need add user
task kwargs.
user_task.delay(user=user)
than you'll able filter results thees functions kwarg user
in result: [{'worker1.example.com': [{'eta': '2010-06-07 09:07:52', 'priority': 0, 'request': { 'name': 'tasks.usertask', 'id': '1a7980ea-8b19-413e-91d2-0b74f3844c4d', 'args': '[]', 'kwargs': '{
'user':'7'}'}}, ...
the problem here - slow.
Comments
Post a Comment