Class: ActiveInteractor::Interactor::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/active_interactor/interactor/worker.rb

Overview

A worker class responsible for thread safe execution

of interactor {.perform} methods.

Author:

Since:

  • 0.0.2

Version:

  • 0.1

Instance Method Summary collapse

Constructor Details

#initialize(interactor) ⇒ ActiveInteractor::Interactor::Worker

Parameters:

Since:

  • 0.0.2



17
18
19
# File 'lib/active_interactor/interactor/worker.rb', line 17

def initialize(interactor)
  @interactor = clone_interactor(interactor)
end

Instance Method Details

#execute_performActiveInteractor::Context::Base

Returns:

Since:

  • 0.0.2



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

Returns:

Raises:

Since:

  • 0.0.2



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_rollbackBoolean

Returns:

  • (Boolean)

    ‘true` if rolled back successfully or `false` if already rolled back

Since:

  • 0.0.2



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