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
8
9
class DoWork
  include Interactor

  delegate :name, to: :context

  def call
    # Do something here
  end
end

Basic interactor to hold business logic, invoke from a controller, scheduled job, or wherever.