Skip to content

Commit

Permalink
RedisBroker: Leave existing max_concurrency values alone
Browse files Browse the repository at this point in the history
- Leave already-set concurrency values alone, always.
- Fix some unit tests that were throwing `InvalidJobSignatureError` errors
- Fix incompatibilties with tox >= 4.0

Fixes: Issue #27
  • Loading branch information
nisimond committed Nov 28, 2023
1 parent 6e3356e commit aab97c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
9 changes: 4 additions & 5 deletions spinach/brokers/redis_scripts/set_concurrency_keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ for i=3, #ARGV do
if max_concurrency ~= -1 then
new_task_names[task["name"]] = true

-- Override max_concurrency whatever it is already set to, if
-- anything.
redis.call('hset', max_concurrency_key, task["name"], max_concurrency)
-- Check to see if current_concurrency exists before initialising
-- it.
-- Check to see if concurrency keys exist before initialising them.
if redis.call('hexists', current_concurrency_key, task["name"]) == 0 then
redis.call('hset', max_concurrency_key, task["name"], max_concurrency)
end
if redis.call('hexists', current_concurrency_key, task["name"]) == 0 then
redis.call('hset', current_concurrency_key, task["name"], 0)
end
Expand Down
8 changes: 4 additions & 4 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def test_schedule_at(patch_now):
s = Engine(broker, namespace='tests')
s.attach_tasks(tasks)

job = s.schedule_at('bar_task', now, three=True)
job = s.schedule_at('bar_task', now)

bar_job = broker.enqueue_jobs.call_args[0][0][0]
assert bar_job == job
assert bar_job.task_name == 'bar_task'
assert bar_job.at == now
assert bar_job.task_args == ()
assert bar_job.task_kwargs == {'three': True}
assert bar_job.task_kwargs == {}


def test_schedule(patch_now):
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_schedule_batch(patch_now):

batch = Batch()
batch.schedule('foo_task', 1, 2)
batch.schedule_at('bar_task', now, three=True)
batch.schedule_at('bar_task', now)
jobs = s.schedule_batch(batch)

broker.enqueue_jobs.assert_called_once_with([ANY, ANY])
Expand All @@ -118,7 +118,7 @@ def test_schedule_batch(patch_now):
assert bar_job.task_name == 'bar_task'
assert bar_job.at == now
assert bar_job.task_args == ()
assert bar_job.task_kwargs == {'three': True}
assert bar_job.task_kwargs == {}


def test_execute(spin):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ envdir =
py3: {toxworkdir}/py3
pep8: {toxworkdir}/py3
usedevelop = True
whitelist_externals =
allowlist_externals =
docker-compose
deps =
pytest
Expand Down

0 comments on commit aab97c3

Please sign in to comment.