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

fix: RedisBroker: Remove non-idempotent jobs from running, too #46

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 7 additions & 9 deletions spinach/brokers/redis.py
Copy link
Contributor Author

@0xDEC0DE 0xDEC0DE May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enable "Hide whitespace" mode for maximum comedy.

Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,13 @@ def get_jobs_from_queue(self, queue: str, max_jobs: int) -> List[Job]:
return jobs

def remove_job_from_running(self, job: Job):
if job.max_retries > 0:
self._run_script(
self._remove_job_from_running,
self._to_namespaced(RUNNING_JOBS_KEY.format(self._id)),
self._to_namespaced(MAX_CONCURRENCY_KEY),
self._to_namespaced(CURRENT_CONCURRENCY_KEY),
job.serialize(),
)

self._run_script(
self._remove_job_from_running,
self._to_namespaced(RUNNING_JOBS_KEY.format(self._id)),
self._to_namespaced(MAX_CONCURRENCY_KEY),
self._to_namespaced(CURRENT_CONCURRENCY_KEY),
job.serialize(),
)
self._something_happened.set()

def _subscriber_func(self):
Expand Down
1 change: 1 addition & 0 deletions tests/test_redis_brokers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def test_running_job(broker):
)
# Try to remove it, even if it doesn't exist in running
broker.remove_job_from_running(job)
assert broker._r.hget(running_jobs_key, str(job.id)) is None

# Idempotent job - get from queue
job = Job('foo_task', 'foo_queue', datetime.now(timezone.utc), 10)
Expand Down