How to list the queued items in celery?

后端 未结 2 1351
南笙
南笙 2020-12-17 22:41

I have a Django project on an Ubuntu EC2 node, which I have been using to set up an asynchronous using Celery.

I am following http://michal.karzynski.p

相关标签:
2条回答
  • 2020-12-17 23:20

    Here is a copy-paste solution for Redis:

    def get_celery_queue_len(queue_name):
        from yourproject.celery import app as celery_app
        with celery_app.pool.acquire(block=True) as conn:
            return conn.default_channel.client.llen(queue_name)
    
    
    def get_celery_queue_items(queue_name):
        import base64
        import json
        from yourproject.celery import app as celery_app
    
        with celery_app.pool.acquire(block=True) as conn:
            tasks = conn.default_channel.client.lrange(queue_name, 0, -1)
    
        decoded_tasks = []
    
        for task in tasks:
            j = json.loads(task)
            body = json.loads(base64.b64decode(j['body']))
            decoded_tasks.append(body)
    
        return decoded_tasks
    

    It works with Django. Just don't forget to change yourproject.celery.

    0 讨论(0)
  • 2020-12-17 23:24

    If you want to get all scheduled tasks,

    celery inspect scheduled
    

    To find all active queues

    celery inspect active_queues
    

    For status

    celery inspect stats
    

    For all commands

    celery inspect
    

    If you want to get it explicitily.Since you are using redis as queue.Then

    redis-cli
    
    >KEYS * #find all keys
    

    Then find out something related to celery

    >LLEN KEY # i think it gives length of list
    
    0 讨论(0)
提交回复
热议问题