-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e16e5f
commit e365be1
Showing
18 changed files
with
529 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
defmodule Exq.Middleware.Unique do | ||
@behaviour Exq.Middleware.Behaviour | ||
alias Exq.Redis.JobQueue | ||
alias Exq.Middleware.Pipeline | ||
|
||
def before_work( | ||
%Pipeline{assigns: %{job_serialized: job_serialized, redis: redis, namespace: namespace}} = | ||
pipeline | ||
) do | ||
job = Exq.Support.Job.decode(job_serialized) | ||
|
||
case job do | ||
%{unique_until: "start", unique_token: unique_token, retry_count: retry_count} | ||
when retry_count in [0, nil] -> | ||
{:ok, _} = JobQueue.unlock(redis, namespace, unique_token) | ||
|
||
_ -> | ||
:ok | ||
end | ||
|
||
pipeline | ||
end | ||
|
||
def after_processed_work( | ||
%Pipeline{assigns: %{job_serialized: job_serialized, redis: redis, namespace: namespace}} = | ||
pipeline | ||
) do | ||
job = Exq.Support.Job.decode(job_serialized) | ||
|
||
case job do | ||
%{unique_until: "success", unique_token: unique_token} -> | ||
{:ok, _} = JobQueue.unlock(redis, namespace, unique_token) | ||
|
||
_ -> | ||
:ok | ||
end | ||
|
||
pipeline | ||
end | ||
|
||
def after_failed_work(pipeline) do | ||
pipeline | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.