Flask-RQ2
Flask-RQ2 copied to clipboard
List running workers
Is there a way to get a list of all currently running workers?
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 :)