koudelka / honeydew

Job Queue for Elixir. Clustered or Local. Straight BEAM. Optional Ecto. 💪🍈
MIT License
724 stars 59 forks source link

Clear an entire queue #101

Closed darksheik closed 4 years ago

darksheik commented 4 years ago

I found this example for clearing out a job when I know the exact arguments.

Is there any way to just whack every job in the entire queue? I've tried matching on just an empty %{} but it gives me an ArgumentError. In fact, the below example gives me that as well, even though it won't match my own arguments. I assume it would just tell me it doesn't match anything or return an empty list instead of the error.

I'm using an ErlangQueue.

# find the job that would run with the argument `10`, as it wont have started yet
# and cancel it
:ok =
  Honeydew.filter(:my_queue, %{task: {:run, [10]}})
  |> List.first
  |> Honeydew.cancel
koudelka commented 4 years ago

Hey Don,

Explicit matches are only supported by the Mnesia queue, the ErlangQueue implementation only takes a function. Check out the docs for more info.

Try this:

alias Honeydew.Job

:ok =
  Honeydew.filter(:my_queue, fn
    %Job{task: {:run, [10]}} ->
     true
    _ ->
     false
  end)
  |> List.first
  |> Honeydew.cancel