Skip to content

Commit

Permalink
Delete expired groups from registry (#2150)
Browse files Browse the repository at this point in the history
  • Loading branch information
eswolinsky3241 authored Nov 20, 2024
1 parent a07b23b commit fb017d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rq/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ def fetch(cls, name: str, connection: Redis):
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:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,11 @@ def test_all_returns_all_groups(self):
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) == []

0 comments on commit fb017d2

Please sign in to comment.