Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resque showing job as processed despite raised exception in Exq #242

Open
eidge opened this issue Mar 7, 2017 · 3 comments
Open

Resque showing job as processed despite raised exception in Exq #242

eidge opened this issue Mar 7, 2017 · 3 comments

Comments

@eidge
Copy link

eidge commented Mar 7, 2017

Hey there guys,

I'm using Exq to process some of our resque jobs in elixir. Everything is working and I'm able to enqueue jobs on the Ruby side and process them in the Elixir side with Exq.

The only problem is that I'm forcing my job to raise an exception in some cases and was expecting the failed job to show on Resque, but it just shows a successfully processed job instead.

My job looks like this:

defmodule SendMessage do
  @moduledoc """
  Exq worker to consume notification requests from redis.
  """

  alias CherAmi.MessageHandler
  alias CherAmiWeb.Mappers.MessageMapper

  def perform(message) do
    result = message
    |> MessageMapper.map
    |> MessageHandler.notify

    case result do
      {:ok, message} -> true
      {:error, errors} ->
        raise(ArgumentError, "Message is invalid. Message: #{inspect message}")
    end
  end
end

And Exq acknowledges the raised exception:

[error] Process #PID<0.481.0> raised an exception
** (ArgumentError) Message is invalid. Message: %{"data" => %{"key" => "created", "resource_id" => 251911, "resource_type" => "alarm", "text" => "New high warning for Simões"}, "user_ids" => [1366, 1624, 1626, 1767, 1633, 1632, 1634, 1635, 1623, 1636, 1620]}
    (cher_ami_redis) lib/send_message.ex:19: SendMessage.perform/1
    (exq) lib/exq/worker/server.ex:119: anonymous fn/3 in Exq.Worker.Server.dispatch_work/2

But resque still shows this as a success.

Am I doind something wrong or is this a bug?

@eidge
Copy link
Author

eidge commented Mar 7, 2017

Actually even Exq.Api.stats reports all as processed and none as failed.

@akira
Copy link
Owner

akira commented Mar 8, 2017

@eidge Please note that by default, failed items will be retried. You can change this in config though to 0 retries, which would then be counted as failed after one error.

See this session below:

iex(2)> 

defmodule MyTest do
   def perform do
      raise(ArgumentError, "Message is invalid. Message:")
   end
end

iex(17)> Exq.enqueue(Exq, "default", MyTest, [])
{:ok, "4d6ab221-55ca-40a8-b88b-dcf9a3942d57"}
iex(18)>
2017-03-07 20:52:59.311 [info]: Elixir.MyTest[4d6ab221-55ca-40a8-b88b-dcf9a3942d57] start

2017-03-07 20:52:59.315 [error]: Process #PID<0.467.0> raised an exception
** (ArgumentError) Message is invalid. Message:
    iex:18: MyTest.perform/0
    (exq) lib/exq/worker/server.ex:119: anonymous fn/3 in Exq.Worker.Server.dispatch_work/2

2017-03-07 20:52:59.315 [info]: Queueing job 4d6ab221-55ca-40a8-b88b-dcf9a3942d57 to retry in 36.0 seconds

2017-03-07 20:52:59.316 [info]: {%ArgumentError{message: "Message is invalid. Message: "},
 [{MyTest, :perform, 0, [file: 'iex', line: 18]},
  {Exq.Worker.Server, :"-dispatch_work/2-fun-0-", 3,
   [file: 'lib/exq/worker/server.ex', line: 119]}]}

2017-03-07 20:52:59.316 [info]: Elixir.MyTest[4d6ab221-55ca-40a8-b88b-dcf9a3942d57] fail: 5ms sec

iex(21)> Exq.Api.retries(Exq.Api)
{:ok,
 [%Exq.Support.Job{args: [], class: "MyTest", enqueued_at: 1488948779.297586,
   error_class: nil,
   error_message: "{%ArgumentError{message: \"Message is invalid. Message: \"},\n [{MyTest, :perform, 0, [file: 'iex', line: 18]},\n  {Exq.Worker.Server, :\"-dispatch_work/2-fun-0-\", 3,\n   [file: 'lib/exq/worker/server.ex', line: 119]}]}",
   failed_at: 1488948909.748436, finished_at: nil,
   jid: "4d6ab221-55ca-40a8-b88b-dcf9a3942d57", processor: nil,
   queue: "default", retry: 25, retry_count: 3}]}

It should be in the "retries" list as above. Is this happening to you also? If not, maybe can you give a script or file to replicate it?

@eidge
Copy link
Author

eidge commented Mar 8, 2017

Hey there @akira, I have set the retries to 0 actually.

I'll try to create a reproducible example tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants