Passing lambda to exq job

Is it a good idea to pass lambda to exq job. How it will behave after code upgrade ? I am trying to build abstraction layer over some code. Passing lambda seems easy but I am worried because I have faced some serialization issue while working on rails. Basically old failed job serialized some methods which were changed.

It’s best to use some form of {module, function, args} or &Module.function(&1, arg1, arg2.., argN)1.

See here and here.

So doing something like

fn x -> 
  {y, z} = fabulate(x)
  send(y, z)  
end

would cause problems, but, on the other hand:

A fully qualified fun (fun Mod:Fun/Arity) will however be a fully
qualified function that doesn’t refer to any specific code version and
will be reloadable.

http://erlang.org/pipermail/erlang-questions/2014-June/079396.html

And here’s one more from Jose Valim: r/1 destroying anonymous functions · Issue #6003 · elixir-lang/elixir · GitHub

I guess you could get away with it if you’re careful, but I’d rather play it safe and use {module, function, args}

1 I haven’t verified if this form will survive a code reload.

1 Like