Skip to content

Commit

Permalink
Add Verk.RetrySet.delete_job/1
Browse files Browse the repository at this point in the history
It will accept the job with the original json or the json itself
  • Loading branch information
Eduardo Gurgel committed Jan 21, 2016
1 parent 260bcca commit d7a7524
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
18 changes: 17 additions & 1 deletion lib/verk/retry_set.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
defmodule Verk.RetrySet do
@moduledoc """
This module interacts with the jobs on the retry set
"""
alias Verk.Job

@retry_key "retry"

@doc """
Expand All @@ -15,7 +20,18 @@ defmodule Verk.RetrySet do
@spec range(integer, integer) :: [Verk.Job.T]
def range(start \\ 0, stop \\ -1) do
for job <- Redix.command!(Verk.Redis, ["ZRANGE", @retry_key, start, stop]) do
Poison.decode!(job, as: Verk.Job)
Job.decode!(job)
end
end

@doc """
Deletes the job from the retry set
"""
@spec delete_job(%Job{} | binary) :: boolean
def delete_job(%Job{ original_json: original_json }) do
Redix.command!(Verk.Redis, ["ZREM", @retry_key, original_json]) == 1
end
def delete_job(original_json) do
Redix.command!(Verk.Redis, ["ZREM", @retry_key, original_json]) == 1
end
end
24 changes: 22 additions & 2 deletions test/retry_set_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,32 @@ defmodule Verk.RetryTest do

test "range" do
job = %Verk.Job{class: "Class", args: []}
Redix.command!(Verk.Redis, ~w(ZADD retry 123 #{Poison.encode!(job)}))
json = Poison.encode!(job)
Redix.command!(Verk.Redis, ~w(ZADD retry 123 #{json}))

assert range == [job]
assert range == [%{ job | original_json: json }]
end

test "range with no items" do
assert range == []
end

test "delete_job having job with original_json" do
job = %Verk.Job{class: "Class", args: []}
json = Poison.encode!(job)

Redix.command!(Verk.Redis, ~w(ZADD retry 123 #{json}))

job = %{ job | original_json: json}

assert delete_job(job) == true
end

test "delete_job with original_json" do
json = %Verk.Job{class: "Class", args: []} |> Poison.encode!

Redix.command!(Verk.Redis, ~w(ZADD retry 123 #{json}))

assert delete_job(json) == true
end
end

0 comments on commit d7a7524

Please sign in to comment.