samsondav/rihanna

Make `use Rihanna` available

tiagonbotelho opened this issue ยท 5 comments

Would it make sense to add the functionality to use Rihanna and expose the enqueue and schedule methods?

My personal use case is that I am running an umbrella application and one of those apps is tasked with managing the workers. I was thinking of isolating the Rihanna dependency exclusively to that app and expose it through a module (that would use Rihanna) to the other apps, like so:

defmodule My.Worker do
  use Rihanna
end

So then I could do something like: My.Worker.enqueue(...)

Thanks ๐Ÿ™‡

Right now I am going around the issue by doing:

defmodule My.Worker do
  defdelegate enqueue(module, args \\ []), to: Rihanna
end
lpil commented

Hi there!

I'd like to avoid metaprogramming unless there is a clear advantage. I'm especially weary of metaprogramming in small wrapper functions such as this one as these wrappers are not a one-size fits all solution. With libraries that default to creating functions like these (i.e. Swoosh, Paginator, Scrivener) I've had to either push patches upstream or copy their macro entirely to my codebase as their set of assumptions didn't match our requirements.

Passing a behaviour module to a function is a well established pattern both Elixir and Erlang (GenServer is a good example) and other than being slightly more verbose it poses no disadvantages to an approach that leverages macros and opaque code-generation.

If the API MyApp.MyJob.enqueue([arg1, arg2]) fits your use case better I would advise creating this function yourself in your project as you are currently.

Thanks for clearing this for me @lpil ๐Ÿ™‡ I do think it will make sense to define my own method that all the workers can extend!

Closing the issue

lpil commented

Great, thank you. Let us know if there is anything else we can help with!

lpil commented

Btw say hi to Steve for me! I believe he's at Duffel!