Skip to content

Commit

Permalink
queue_job: split identity_key hasher to ease reuse
Browse files Browse the repository at this point in the history
You can now create your own identity exact matcher using the default hasher as a base.
  • Loading branch information
simahawk authored and JordiMForgeFlow committed Oct 24, 2024
1 parent 64aa674 commit 9b9a10b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions queue_job/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b9a10b

Please sign in to comment.