Background workers for Interactors

Curated ago by @dpaola2

Description

This is a simple pattern I use all the time to organize my interactors and background workers. The interactor holds the business logic and the work simply invokes it.

It works great when you start with the logic and as it grows in runtime, put it into a background worker quickly and easily.

It also works great because you can invoke the interactor synchronously for debugging or one-off tasks, or you can perform it in the background for tasks that take longer.

1
2
3
4
5
6
7
class DoWorkJob
  include Sidekiq::Job

  def perform(name)
    DoWork.call(name: name)
  end
end

Dead simple