mirror of https://github.com/rq/rq.git
Delete expired groups from registry (#2150)
This commit is contained in:
parent
a07b23b821
commit
fb017d2c29
|
@ -89,7 +89,13 @@ class Group:
|
|||
def all(cls, connection: 'Redis') -> List['Group']:
|
||||
"Returns an iterable of all Groupes."
|
||||
group_keys = [as_text(key) for key in connection.smembers(cls.REDIS_GROUP_KEY)]
|
||||
return [cls.fetch(key, connection=connection) for key in group_keys]
|
||||
groups = []
|
||||
for key in group_keys:
|
||||
try:
|
||||
groups.append(cls.fetch(key, connection=connection))
|
||||
except NoSuchGroupError:
|
||||
connection.srem(cls.REDIS_GROUP_KEY, key)
|
||||
return groups
|
||||
|
||||
@classmethod
|
||||
def get_key(cls, name: str) -> str:
|
||||
|
|
|
@ -142,3 +142,11 @@ class TestGroup(RQTestCase):
|
|||
assert len(all_groups) == 1
|
||||
assert "group1" in [group.name for group in all_groups]
|
||||
assert "group2" not in [group.name for group in all_groups]
|
||||
|
||||
def test_all_deletes_missing_groups(self):
|
||||
q = Queue(connection=self.connection)
|
||||
group = Group.create(connection=self.connection)
|
||||
jobs = group.enqueue_many(q, [self.job_1_data])
|
||||
jobs[0].delete()
|
||||
assert not self.connection.exists(Group.get_key(group.name))
|
||||
assert Group.all(connection=self.connection) == []
|
||||
|
|
Loading…
Reference in New Issue