Skip to content

Commit

Permalink
Quick fix synchronous redis calls
Browse files Browse the repository at this point in the history
Redis broker calls were synchronous, so blocking the main thread. This
moves them to ThreadPoolExecutor
  • Loading branch information
HTRafal committed Apr 17, 2023
1 parent 933db84 commit 924d2f1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion flower/utils/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ class RedisBase(BrokerBase):
DEFAULT_SEP = '\x06\x16'
DEFAULT_PRIORITY_STEPS = [0, 3, 6, 9]

def __init__(self, broker_url, *args, **kwargs):
def __init__(self, broker_url, io_loop=None, *args, **kwargs):
super(RedisBase, self).__init__(broker_url)
self.io_loop = io_loop or ioloop.IOLoop.instance()
self.redis = None

if not redis:
Expand All @@ -118,6 +119,11 @@ def _q_for_pri(self, queue, pri):

@gen.coroutine
def queues(self, names):
# TODO: use redis.asyncio instead of synchronous client with ThreadPoolExecutor
queue_sizes = yield self.io_loop.run_in_executor(None, self._queues_synchronous, names)
raise gen.Return(queue_sizes)

def _queues_synchronous(self, names):
queue_stats = []
for name in names:
priority_names = [self.broker_prefix + self._q_for_pri(
Expand Down

0 comments on commit 924d2f1

Please sign in to comment.