collectiveidea / interactor

Interactor provides a common interface for performing complex user interactions.
MIT License
3.36k stars 212 forks source link

Best practice with DelayedJob? #29

Closed bradobro closed 10 years ago

bradobro commented 10 years ago

@laserlemon

Hey Steve, thanks for cluing me in to this library.

Have you guys played with tossing organizers at a DelayedJob queue?

ersatzryan commented 10 years ago

Hey @bradobro,

We have done some background jobs with interactors.

One thing that is fairly easy and helpful to do for interactors that might be run as background or not is to make use of the setup method (described in the README).

  def setup
    context[:user] ||= User.find(user_id)
  end

This gives you the ability to pass in a context containing user: u or user_id: 1.

There isn't too much magic in either Interactor or Interactor::Organizer so there shouldn't be many issues with them running in the background.

Let us know if you have more specific questions on using it in DelayedJob.

bradobro commented 10 years ago

Thanks @ersatzryan!

bradobro commented 10 years ago

Hey @ersatzryan, maybe I missed it, but I don't see Interactor#setup mentioned in the README.md. Since it's called in Interactor#initialize after setting up .context, I'm guessing normal use is for consistent, dynamic preprocessing of .context--and probably the exception to the never modify context values guideline.

Does that sound right?

ersatzryan commented 10 years ago

#setup not being in the README is just an oversight. Thanks for bringing it to our attention.

Yes, we usually use the setup as a way to massage the context prior to perform.

bradobro commented 10 years ago

Thanks again Ryan