diff --git a/tasktiger/_internal.py b/tasktiger/_internal.py index a5e1dacb..35204385 100644 --- a/tasktiger/_internal.py +++ b/tasktiger/_internal.py @@ -62,16 +62,15 @@ 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. """ + data = { + 'func': serialized_name, + 'args': args, + 'kwargs': kwargs, + } + if queue is not None: + data['queue'] = queue return hashlib.sha256( - json.dumps( - { - 'queue': queue, - 'func': serialized_name, - 'args': args, - 'kwargs': kwargs, - }, - sort_keys=True, - ).encode('utf8') + json.dumps(data, sort_keys=True).encode('utf8') ).hexdigest() diff --git a/tasktiger/worker.py b/tasktiger/worker.py index beb4cdb7..66e12e89 100644 --- a/tasktiger/worker.py +++ b/tasktiger/worker.py @@ -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: