Flask-RQ2 icon indicating copy to clipboard operation
Flask-RQ2 copied to clipboard

List running workers

Open moi90 opened this issue 5 years ago • 1 comments

Is there a way to get a list of all currently running workers?

moi90 avatar Jun 29 '19 15:06 moi90

Hey,

Check out https://github.com/eoranged/rq-dashboard. Very useful to monitor RQ.

Assume that we have initialized RQ and app:

# Initialization part
from flask import Flask
from flask_rq2 import RQ

app = Flask(__name__)
rq = RQ()

rq.init_app(rq)

To get all workers:

from rq import Worker
from rq.utils import import_attribute

# For default Worker class from RQ module:
workers = Worker.all(connection=rq.connection)

# For any Worker class
workers = import_attribute(rq.worker_class).all(connection=rq.connection)

(Additionally) To get list of workers for specified queue:

workers = Worker.all(queue=rq.get_queue('default'))
# or
workers = import_attribute(rq.worker_class).all(queue=rq.get_queue('default'))

Let me now if you need more info :)

AlexanderPashuk avatar Aug 13 '19 19:08 AlexanderPashuk