akira / exq

Job processing library for Elixir - compatible with Resque / Sidekiq
Other
1.51k stars 182 forks source link

Incompatibility with Elixir 1.4 #232

Closed tmaszk closed 7 years ago

tmaszk commented 7 years ago

I'm upgrading my project to Elixir 1.4, but Exq doesn't seem to work properly. I recreated the problem with a fresh project and received the same results.

Steps to reproduce:

  1. mix new exqtest
  2. Add {:exq, "~> 0.8.3"} to deps in mix.exs, and run mix deps.get
  3. Add default :exq config to config/config.exs
  4. Add a simple Worker module, such as
    defmodule Worker do
    def perform do
    IO.puts "Did it"
    end
    end
  5. run iex -S mix
  6. Exq.enqueue(Exq, "default", Worker, [])
  7. receive error message
    10:00:34.656 [error] GenServer Exq.Enqueuer terminating
    ** (Poison.EncodeError) unable to encode value: {[], [:retry | 25], [], {:class, "Worker", {[], [], [], [], [:args], [], [], []}}, {:jid, "df8b7ebc-f113-48f5-835c-a86c6c98e5a1", {[], [], [], [], [], [], [:enqueued_at | 1486652434.630006], []}}, [:queue | "default"], [], []}
    lib/poison/encoder.ex:383: Poison.Encoder.Any.encode/2
    lib/poison/encoder.ex:227: anonymous fn/4 in Poison.Encoder.Map.encode/3
    lib/poison/encoder.ex:228: Poison.Encoder.Map."-encode/3-lists^foldl/2-0-"/3
    lib/poison/encoder.ex:228: Poison.Encoder.Map.encode/3
    lib/poison.ex:41: Poison.encode!/2
    (exq) lib/exq/redis/job_queue.ex:368: Exq.Redis.JobQueue.to_job_serialized/5
    (exq) lib/exq/redis/job_queue.ex:23: Exq.Redis.JobQueue.enqueue/6
    (exq) lib/exq/enqueuer/server.ex:39: Exq.Enqueuer.Server.handle_cast/2
    Last message: {:"$gen_cast", {:enqueue, {#PID<0.183.0>, #Reference<0.0.6.2874>}, "default", Worker, [], []}}
    State: %Exq.Enqueuer.Server.State{namespace: "exq", redis: Exq.Redis.Client}
    ** (exit) exited in: GenServer.call(Exq, {:enqueue, "default", Worker, [], []}, 5000)
    ** (EXIT) time out
    (elixir) lib/gen_server.ex:737: GenServer.call/3
akira commented 7 years ago

@tmaszk I am unable to replicate this.

Using elixir 1.4:

akira@Alexs-MacBook-Pro ~/development/erlang/exq (master) $ elixir --version
Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]

Elixir 1.4.0
iex(2)> defmodule Worker do
...(2)>   def perform do
...(2)>     IO.puts "Did it"
...(2)>   end
...(2)> end
{:module, Worker,
 <<70, 79, 82, 49, 0, 0, 5, 12, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 0, 130,
   131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115,
   95, 118, 49, 108, 0, 0, 0, 4, 104, 2, ...>>, {:perform, 0}}
iex(3)> Exq.enqueue(Exq, "default", Worker, [])
{:ok, "9a8989d7-6812-499d-8e85-392fd8042d10"}
iex(4)>
2017-02-09 19:34:08.064 [info]: Elixir.Worker[9a8989d7-6812-499d-8e85-392fd8042d10] start
Did it

2017-02-09 19:34:08.065 [info]: Elixir.Worker[9a8989d7-6812-499d-8e85-392fd8042d10] done: 794µs sec

Are you sure that the worker module is loaded correctly? If so can you paste your mix.lock file.

akira commented 7 years ago

@tmaszk looks like a dependency issue, I can take a look. If you can post your mix.lock file to see what you're using that could also help.

akira commented 7 years ago

@tmaszk can you try against the latest master?

tmaszk commented 7 years ago

@akira I retested with the latest master and confirmed that the issue is fixed. Thanks for the quick response.

drapergeek commented 7 years ago

I seem to be running into the same type of issue with encoding structs. I'm using an up to date version of the app (tried master) as well as poison (2.0). I'm on Elixir 1.4 but I don't know if that has anything to do with it. If you have any ideas @akira I would greatly appreciate it. Thanks!

akira commented 7 years ago

@drapergeek can you post more info on your exact error and which versions of the other stuff are you running. I can't seem to reproduce even with Elixir 1.4 and different versions of Poison.

drapergeek commented 7 years ago

Certainly!

The error:

** (Poison.EncodeError) unable to encode value: {:sub_area, "tac"}
    (poison) lib/poison/encoder.ex:354: Poison.Encoder.Any.encode/2
    (poison) lib/poison/encoder.ex:232: anonymous fn/3 in Poison.Encoder.List.encode/3
    (poison) lib/poison/encoder.ex:233: Poison.Encoder.List."-encode/3-lists^foldr/2-1-"/3
    (poison) lib/poison/encoder.ex:233: Poison.Encoder.List.encode/3
    (poison) lib/poison/encoder.ex:232: anonymous fn/3 in Poison.Encoder.List.encode/3
    (poison) lib/poison/encoder.ex:233: Poison.Encoder.List."-encode/3-lists^foldr/2-1-"/3
    (poison) lib/poison/encoder.ex:233: Poison.Encoder.List.encode/3
    (poison) lib/poison/encoder.ex:213: anonymous fn/4 in Poison.Encoder.Map.encode/3
    (poison) lib/poison/encoder.ex:214: Poison.Encoder.Map."-encode/3-lists^foldl/2-0-"/3
    (poison) lib/poison/encoder.ex:214: Poison.Encoder.Map.encode/3
    (poison) lib/poison.ex:41: Poison.encode!/2
    (exq) lib/exq/redis/job_queue.ex:366: Exq.Redis.JobQueue.to_job_serialized/5
    (exq) lib/exq/redis/job_queue.ex:22: Exq.Redis.JobQueue.enqueue/6
    (exq) lib/exq/enqueuer/server.ex:39: Exq.Enqueuer.Server.handle_cast/2
    (stdlib) gen_server.erl:601: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:667: :gen_server.handle_msg/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: {:"$gen_cast", {:enqueue, {#PID<0.587.0>, #Reference<0.0.3.5889>}, "craigslist", Joydrive.Craigslist, [%Vehicle{deals: #Ecto.Association.NotLoaded<association :deals is not loaded>, exterior_options: [], safety_options: [], cargo_options: [], updated_at: #<DateTime(2017-

Poison: 2.2 and Elixir 1.4

Any other info I can provide to be helpful?

akira commented 7 years ago

@drapergeek This parameter is not coming from Exq, is this something you're sending as a worker parameter?

> Poison.encode!({:sub_area, "tac"})
** (Poison.EncodeError) unable to encode value: {:sub_area, "tac"}
    lib/poison/encoder.ex:383: Poison.Encoder.Any.encode/2
    lib/poison.ex:41: Poison.encode!/2

You can send this this as a list and it should work:

> Poison.encode!([:sub_area, "tac"])
"[\"sub_area\",\"tac\"]"