Created
August 20, 2012 21:02
-
-
Save slackorama/3407863 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# active-celery.py --- get the active tasks being processed from celery and | |
# sort by how long they have been running (descending) | |
from celery import Celery | |
from time import time | |
if __name__ == '__main__': | |
celery = Celery('monitoring') | |
celery.config_from_object('celeryconfig') | |
active = celery.control.inspect().active() | |
all_tasks = [] | |
if active is not None: | |
for node, tasks in active.items(): | |
all_tasks += tasks | |
if len(all_tasks) > 0: | |
sorted_tasks = sorted(all_tasks, key=lambda task: | |
task.get('time_start',0)) | |
for task in sorted_tasks: | |
print('{0:0.2f} {1} {2}'.format(time()-task.get('time_start',0), | |
task['id'], | |
task['worker_pid'])) | |
else: | |
print('No tasks found...uh yay?') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment