Class: ActiveInteractor::Interactor::Worker
- Inherits:
-
Object
- Object
- ActiveInteractor::Interactor::Worker
- Defined in:
- lib/active_interactor/interactor/worker.rb
Overview
A worker class responsible for thread safe execution
of interactor {.perform} methods.
Instance Method Summary collapse
-
#execute_perform ⇒ ActiveInteractor::Context::Base
Calls #execute_perform! and rescues Context::Failure.
-
#execute_perform! ⇒ ActiveInteractor::Context::Base
Calls #perform with callbacks and context validation.
-
#execute_rollback ⇒ Boolean
Calls #rollback with callbacks.
-
#initialize(interactor) ⇒ ActiveInteractor::Interactor::Worker
constructor
A new instance of Worker.
Constructor Details
#initialize(interactor) ⇒ ActiveInteractor::Interactor::Worker
A new instance of ActiveInteractor::Interactor::Worker
17 18 19 |
# File 'lib/active_interactor/interactor/worker.rb', line 17 def initialize(interactor) @interactor = clone_interactor(interactor) end |
Instance Method Details
#execute_perform ⇒ ActiveInteractor::Context::Base
Calls #execute_perform! and rescues Context::Failure
23 24 25 26 27 28 |
# File 'lib/active_interactor/interactor/worker.rb', line 23 def execute_perform execute_perform! rescue ActiveInteractor::Context::Failure => exception ActiveInteractor.logger.error("ActiveInteractor: #{exception}") context end |
#execute_perform! ⇒ ActiveInteractor::Context::Base
Calls ActiveInteractor::Interactor#perform with callbacks and context validation
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/active_interactor/interactor/worker.rb', line 33 def execute_perform! run_callbacks :perform do perform! finalize_context! context rescue # rubocop:disable Style/RescueStandardError context.rollback! raise end end |
#execute_rollback ⇒ Boolean
Calls ActiveInteractor::Interactor#rollback with callbacks
47 48 49 50 51 |
# File 'lib/active_interactor/interactor/worker.rb', line 47 def execute_rollback run_callbacks :rollback do interactor.rollback end end |