Skip to content

Commit

Permalink
Don't change key for locks
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasst committed Mar 21, 2021
1 parent 0e2a4fb commit 1cff32c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
19 changes: 8 additions & 11 deletions tasktiger/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,14 @@ def gen_unique_id(queue, serialized_name, args, kwargs):
Generates and returns a hex-encoded 256-bit ID for the given task name and
args. Used to generate IDs for unique tasks or for task locks.
"""
return hashlib.sha256(
json.dumps(
{
'queue': queue,
'func': serialized_name,
'args': args,
'kwargs': kwargs,
},
sort_keys=True,
).encode('utf8')
).hexdigest()
data = {
'func': serialized_name,
'args': args,
'kwargs': kwargs,
}
if queue is not None:
data['queue'] = queue
return hashlib.sha256(json.dumps(data, sort_keys=True).encode('utf8')).hexdigest()


def serialize_func_name(func):
Expand Down
3 changes: 2 additions & 1 deletion tasktiger/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,13 +857,14 @@ def _execute_task_group(self, queue, tasks, all_task_ids, queue_lock):
if task.lock_key:
kwargs = task.kwargs
lock_id = gen_unique_id(
None,
task.serialized_func,
None,
{key: kwargs.get(key) for key in task.lock_key},
)
else:
lock_id = gen_unique_id(
task.serialized_func, task.args, task.kwargs
None, task.serialized_func, task.args, task.kwargs
)

if lock_id not in lock_ids:
Expand Down

0 comments on commit 1cff32c

Please sign in to comment.