Class: CircuitBreaker::Executors::NatsExecutor

Inherits:
BaseExecutor
  • Object
show all
Defined in:
lib/circuit_breaker/executors/nats_executor.rb

Overview

Executor class that uses NATS for workflow event distribution Handles workflow state management and event processing

Instance Attribute Summary collapse

Attributes inherited from BaseExecutor

#context, #result

Instance Method Summary collapse

Methods included from DSL

included, #validate_parameters

Constructor Details

#initialize(context = {}) ⇒ NatsExecutor

Initialize a new NATS executor

Parameters:

  • context (Hash) (defaults to: {})

    Initialization context

Options Hash (context):

  • :nats_url (String)

    URL of the NATS server (default: ‘nats://localhost:4222’)



19
20
21
22
23
24
# File 'lib/circuit_breaker/executors/nats_executor.rb', line 19

def initialize(context = {})
  super
  @nats_url = context[:nats_url] || 'nats://localhost:4222'
  @nats = NATS.connect(@nats_url)
  setup_jetstream
end

Instance Attribute Details

#natsObject (readonly)

Reader for NATS client



14
15
16
# File 'lib/circuit_breaker/executors/nats_executor.rb', line 14

def nats
  @nats
end

#workflow_idObject (readonly)

Reader for workflow ID



12
13
14
# File 'lib/circuit_breaker/executors/nats_executor.rb', line 12

def workflow_id
  @workflow_id
end

Instance Method Details

#executeObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/circuit_breaker/executors/nats_executor.rb', line 26

def execute
  return unless @context[:petri_net]

  workflow_id = create_workflow(
    @context[:petri_net],
    workflow_id: @context[:workflow_id]
  )

  @result = {
    workflow_id: workflow_id,
    status: 'completed'
  }
end