Delete expired groups from registry (#2150)

This commit is contained in:
Ethan Wolinsky 2024-11-19 20:08:33 -05:00 committed by GitHub
parent a07b23b821
commit fb017d2c29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -89,7 +89,13 @@ class Group:
def all(cls, connection: 'Redis') -> List['Group']: def all(cls, connection: 'Redis') -> List['Group']:
"Returns an iterable of all Groupes." "Returns an iterable of all Groupes."
group_keys = [as_text(key) for key in connection.smembers(cls.REDIS_GROUP_KEY)] 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 @classmethod
def get_key(cls, name: str) -> str: def get_key(cls, name: str) -> str:

View File

@ -142,3 +142,11 @@ class TestGroup(RQTestCase):
assert len(all_groups) == 1 assert len(all_groups) == 1
assert "group1" in [group.name for group in all_groups] assert "group1" in [group.name for group in all_groups]
assert "group2" not 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) == []