Celery scheduled list returns None

后端 未结 2 1932
灰色年华
灰色年华 2020-12-21 00:58

I\'m fairly new to Celery and I\'ve been attempting setup a simple script to schedule and unschedule tasks. However I feel like I\'m running into a weird issue. I have the f

相关标签:
2条回答
  • 2020-12-21 01:43

    To repeat call to get list of tasks in queues you have to create new instance of Celery object. I was trying to figure out why it's necessary by debugging code executed by calling ./manage.py celery inspect scheduled but without any luck. Maybe someone will have more experience with that and add some additional informations to this answer.

    Try this simple snippet for checking list of scheduled tasks:

    from celery import Celery
    
    def inspect(method):
        app = Celery('app', broker='amqp://')
        return getattr(app.control.inspect(), method)()
    
    print inspect('scheduled')
    print inspect('active')
    
    0 讨论(0)
  • 2020-12-21 01:46

    Thanks to daniula,

    I'm using this code in django-celery-rabbitmq and i need to close app instance aftert inspect... like this:

    from celery import Celery
    
    def inspect(method):
        app = Celery('app', broker='amqp://')
        inspect_result = getattr(app.control.inspect(), method)()
        app.close()
        return inspect_result
    
    print inspect('scheduled')
    print inspect('active')
    

    In my case if i don't call app.close() socket connection to rabbitmq still alive (active), in this way all socket descriptors will be consumed and after that, new socket connection cannot be available, so everything stop to work.

    0 讨论(0)
提交回复
热议问题