Skip to content

Commit 5e52315

Browse files
committed
fix: RedisBroker: Remove non-idempotent jobs from running, too
Adds a test that the running job is actually gone. Fixes: Issue NicolasLM#45
1 parent a3bbea7 commit 5e52315

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

spinach/brokers/redis.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,13 @@ def get_jobs_from_queue(self, queue: str, max_jobs: int) -> List[Job]:
226226
return jobs
227227

228228
def remove_job_from_running(self, job: Job):
229-
if job.max_retries > 0:
230-
self._run_script(
231-
self._remove_job_from_running,
232-
self._to_namespaced(RUNNING_JOBS_KEY.format(self._id)),
233-
self._to_namespaced(MAX_CONCURRENCY_KEY),
234-
self._to_namespaced(CURRENT_CONCURRENCY_KEY),
235-
job.serialize(),
236-
)
237-
229+
self._run_script(
230+
self._remove_job_from_running,
231+
self._to_namespaced(RUNNING_JOBS_KEY.format(self._id)),
232+
self._to_namespaced(MAX_CONCURRENCY_KEY),
233+
self._to_namespaced(CURRENT_CONCURRENCY_KEY),
234+
job.serialize(),
235+
)
238236
self._something_happened.set()
239237

240238
def _subscriber_func(self):

tests/test_redis_brokers.py

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def test_running_job(broker):
8686
)
8787
# Try to remove it, even if it doesn't exist in running
8888
broker.remove_job_from_running(job)
89+
assert broker._r.hget(running_jobs_key, str(job.id)) is None
8990

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

0 commit comments

Comments
 (0)