Skip to content

Commit a5924f4

Browse files
author
Florian Perucki
committed
raw subqueues should use their root queue's config
1 parent 60a19f1 commit a5924f4

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

mrq/queue.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ class Queue(object):
1515
is_set = False
1616
is_reverse = False
1717

18+
# root_id will contain the root queue id without any trailing subqueue delimiter
19+
# e.g. if self.id is "some_queue/" then self.root_id will contain "some_queue"
20+
# and if self.id is "some_queue/some_subqueue" then self.root_id will contain "some_queue"
21+
root_id = None
22+
1823
use_large_ids = False
1924

2025
# This is a mutable type so it is shared by all instances
@@ -47,6 +52,13 @@ def __init__(self, queue_id, add_to_known_queues=False):
4752
if "_sorted" in self.id:
4853
self.is_sorted = True
4954

55+
self.root_id = self.id
56+
57+
delimiter = context.get_current_config().get("subqueues_delimiter")
58+
if delimiter is not None and delimiter in self.id:
59+
# Get the root queue id with no trailing delimiter
60+
self.root_id = self.id.split(delimiter)[0]
61+
5062
self.use_large_ids = context.get_current_config()["use_large_job_ids"]
5163

5264
# If this is the first time this process sees this queue, try to add it
@@ -117,7 +129,7 @@ def redis_known_subqueues(self):
117129
def get_config(self):
118130
""" Returns the specific configuration for this queue """
119131

120-
return context.get_current_config().get("raw_queues", {}).get(self.id) or {}
132+
return context.get_current_config().get("raw_queues", {}).get(self.root_id) or {}
121133

122134
def serialize_job_ids(self, job_ids):
123135
""" Returns job_ids serialized for storage in Redis """

tests/test_raw.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,23 @@ def test_raw_sorted(worker, p_queue, p_pushback, p_timed, p_flags):
7979
assert test_collection.count() == 3
8080

8181

82+
@pytest.mark.parametrize("has_subqueue", [False, True])
8283
@pytest.mark.parametrize(["p_queue", "p_set"], [
8384
["test_raw", False],
8485
["test_set", True]
8586
])
86-
def test_raw_set(worker, p_queue, p_set):
87-
88-
worker.start(
89-
flags="--greenlets 10 --config tests/fixtures/config-raw1.py", queues=p_queue)
87+
def test_raw_set(worker, has_subqueue, p_queue, p_set):
88+
flags = "--greenlets 10 --config tests/fixtures/config-raw1.py"
89+
if has_subqueue:
90+
flags = "%s --subqueues_refresh_interval=0.1" % flags
91+
# worker should dequeue all subqueues
92+
p_queue = "%s/" % p_queue
93+
94+
worker.start(flags=flags, queues=p_queue)
95+
96+
if has_subqueue:
97+
# queue tasks in p_queue/subqueue
98+
p_queue = "%ssubqueue" % p_queue
9099

91100
test_collection = worker.mongodb_logs.tests_inserts
92101
jobs_collection = worker.mongodb_jobs.mrq_jobs

0 commit comments

Comments
 (0)