Class: Sequent::Core::Workflow

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::DescendantsTracker
Includes:
Helpers::MessageHandler
Defined in:
lib/sequent/core/workflow.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::MessageHandler

#dispatch_message, #handle_message, included

Class Attribute Details

.abstract_classObject

Returns the value of attribute abstract_class.



13
14
15
# File 'lib/sequent/core/workflow.rb', line 13

def abstract_class
  @abstract_class
end

.skip_autoregisterObject

Returns the value of attribute skip_autoregister.



13
14
15
# File 'lib/sequent/core/workflow.rb', line 13

def skip_autoregister
  @skip_autoregister
end

Class Method Details

.on(*args, **opts, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sequent/core/workflow.rb', line 16

def self.on(*args, **opts, &block)
  decorated_block = ->(event) do
    begin
      old_event = CurrentEvent.current
      CurrentEvent.current = event
      instance_exec(event, &block)
    ensure
      CurrentEvent.current = old_event
    end
  end
  super(*args, **opts, &decorated_block)
end

Instance Method Details

#after_commit(ignore_errors: false, &block) ⇒ Object

Workflow#after_commit will accept a block to execute after the transaction commits. This is very useful to isolate side-effects. They will run only on the transaction’s success and will not be able to roll it back when there is an exception. Useful if your background jobs processor is not using the same database connection to enqueue jobs.



40
41
42
43
44
45
46
47
48
# File 'lib/sequent/core/workflow.rb', line 40

def after_commit(ignore_errors: false, &block)
  Sequent.configuration.transaction_provider.after_commit(&block)
rescue StandardError => e
  if ignore_errors
    Sequent.logger.warn("An exception was raised in an after_commit hook: #{e}, #{e.inspect}")
  else
    raise e
  end
end

#execute_commands(*commands) ⇒ Object



29
30
31
# File 'lib/sequent/core/workflow.rb', line 29

def execute_commands(*commands)
  Sequent.configuration.command_service.execute_commands(*commands)
end