Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][REF] queue_job: Use set.discard(...) instead of SafeSet #722

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 10 additions & 30 deletions queue_job/jobrunner/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@
def add(self, o):
if o is None:
raise ValueError()
if o in self._removed:
self._removed.remove(o)
self._removed.discard(o)

Check warning on line 78 in queue_job/jobrunner/channels.py

View check run for this annotation

Codecov / codecov/patch

queue_job/jobrunner/channels.py#L78

Added line #L78 was not covered by tests
if o in self._known:
return
self._known.add(o)
Expand All @@ -87,8 +86,7 @@
raise ValueError()
if o not in self._known:
return
if o not in self._removed:
self._removed.add(o)
self._removed.add(o)

Check warning on line 89 in queue_job/jobrunner/channels.py

View check run for this annotation

Codecov / codecov/patch

queue_job/jobrunner/channels.py#L89

Added line #L89 was not covered by tests

def pop(self):
while True:
Expand All @@ -104,24 +102,6 @@
return o


class SafeSet(set):
"""A set that does not raise KeyError when removing non-existent items.

>>> s = SafeSet()
>>> s.remove(1)
>>> len(s)
0
>>> s.remove(1)
"""

def remove(self, o):
# pylint: disable=missing-return,except-pass
try:
super().remove(o)
except KeyError:
pass


@total_ordering
class ChannelJob:
"""A channel job is attached to a channel and holds the properties of a
Expand Down Expand Up @@ -408,8 +388,8 @@
self.parent.children[name] = self
self.children = {}
self._queue = ChannelQueue()
self._running = SafeSet()
self._failed = SafeSet()
self._running = set()
self._failed = set()

Check warning on line 392 in queue_job/jobrunner/channels.py

View check run for this annotation

Codecov / codecov/patch

queue_job/jobrunner/channels.py#L391-L392

Added lines #L391 - L392 were not covered by tests
self._pause_until = 0 # utc seconds since the epoch
self.capacity = capacity
self.throttle = throttle # seconds
Expand Down Expand Up @@ -463,8 +443,8 @@
def remove(self, job):
"""Remove a job from the channel."""
self._queue.remove(job)
self._running.remove(job)
self._failed.remove(job)
self._running.discard(job)
self._failed.discard(job)

Check warning on line 447 in queue_job/jobrunner/channels.py

View check run for this annotation

Codecov / codecov/patch

queue_job/jobrunner/channels.py#L446-L447

Added lines #L446 - L447 were not covered by tests
if self.parent:
self.parent.remove(job)

Expand All @@ -484,8 +464,8 @@
"""
if job not in self._queue:
self._queue.add(job)
self._running.remove(job)
self._failed.remove(job)
self._running.discard(job)
self._failed.discard(job)

Check warning on line 468 in queue_job/jobrunner/channels.py

View check run for this annotation

Codecov / codecov/patch

queue_job/jobrunner/channels.py#L467-L468

Added lines #L467 - L468 were not covered by tests
if self.parent:
self.parent.remove(job)
_logger.debug("job %s marked pending in channel %s", job.uuid, self)
Expand All @@ -498,7 +478,7 @@
if job not in self._running:
self._queue.remove(job)
self._running.add(job)
self._failed.remove(job)
self._failed.discard(job)

Check warning on line 481 in queue_job/jobrunner/channels.py

View check run for this annotation

Codecov / codecov/patch

queue_job/jobrunner/channels.py#L481

Added line #L481 was not covered by tests
if self.parent:
self.parent.set_running(job)
_logger.debug("job %s marked running in channel %s", job.uuid, self)
Expand All @@ -507,7 +487,7 @@
"""Mark the job as failed."""
if job not in self._failed:
self._queue.remove(job)
self._running.remove(job)
self._running.discard(job)

Check warning on line 490 in queue_job/jobrunner/channels.py

View check run for this annotation

Codecov / codecov/patch

queue_job/jobrunner/channels.py#L490

Added line #L490 was not covered by tests
self._failed.add(job)
if self.parent:
self.parent.remove(job)
Expand Down
Loading