samsondav / rihanna

Rihanna is a high performance postgres-backed job queue for Elixir
MIT License
439 stars 47 forks source link

Make `use Rihanna` available #52

Closed tiagonbotelho closed 5 years ago

tiagonbotelho commented 5 years ago

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 🙇

tiagonbotelho commented 5 years ago

Right now I am going around the issue by doing:

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

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.

tiagonbotelho commented 5 years ago

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 5 years ago

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

lpil commented 5 years ago

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