From 68bc63016cbe07271d718bc4b93a9fdcff8dcf7c Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Mon, 27 Nov 2023 10:35:47 +0100 Subject: [PATCH] queue_job: split identity_key hasher to ease reuse You can now create your own identity exact matcher using the default hasher as a base. --- queue_job/job.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/queue_job/job.py b/queue_job/job.py index 7fb39f9450..e0bbe63e88 100644 --- a/queue_job/job.py +++ b/queue_job/job.py @@ -89,14 +89,19 @@ def identity_example(job_): Usually you will probably always want to include at least the name of the model and method. """ + hasher = identity_exact_hasher(job_) + return hasher.hexdigest() + + +def identity_exact_hasher(job_): + """Prepare hasher object for identity_exact.""" hasher = hashlib.sha1() hasher.update(job_.model_name.encode("utf-8")) hasher.update(job_.method_name.encode("utf-8")) hasher.update(str(sorted(job_.recordset.ids)).encode("utf-8")) hasher.update(str(job_.args).encode("utf-8")) hasher.update(str(sorted(job_.kwargs.items())).encode("utf-8")) - - return hasher.hexdigest() + return hasher @total_ordering