Class: ActiveJob::Temporal::ExternalOperation

Inherits:
Object
  • Object
show all
Defined in:
lib/activejob/temporal/external_operation.rb

Constant Summary collapse

ACTIVITY =
"activity"
WORKFLOW =
"workflow"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation, temporal_type, options) ⇒ ExternalOperation

Returns a new instance of ExternalOperation.



34
35
36
37
38
# File 'lib/activejob/temporal/external_operation.rb', line 34

def initialize(operation, temporal_type, options)
  @operation = normalize_operation(operation)
  @temporal_type = normalize_temporal_type(temporal_type)
  @options = ExternalOperationOptions.normalize(@operation, options)
end

Instance Attribute Details

#operationObject (readonly)

Returns the value of attribute operation.



11
12
13
# File 'lib/activejob/temporal/external_operation.rb', line 11

def operation
  @operation
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/activejob/temporal/external_operation.rb', line 11

def options
  @options
end

#temporal_typeObject (readonly)

Returns the value of attribute temporal_type.



11
12
13
# File 'lib/activejob/temporal/external_operation.rb', line 11

def temporal_type
  @temporal_type
end

Class Method Details

.activity(temporal_type, **options) ⇒ Object



13
14
15
# File 'lib/activejob/temporal/external_operation.rb', line 13

def self.activity(temporal_type, **options)
  new(ACTIVITY, temporal_type, options)
end

.external_operation_hash?(value) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/activejob/temporal/external_operation.rb', line 28

def self.external_operation_hash?(value)
  value.respond_to?(:[]) &&
    !payload_value(value, :temporal_operation).nil? &&
    !payload_value(value, :temporal_type).nil?
end

.normalize(value) ⇒ Object



21
22
23
24
25
26
# File 'lib/activejob/temporal/external_operation.rb', line 21

def self.normalize(value)
  return value.to_h if value.is_a?(self)
  return normalize_hash(value) if external_operation_hash?(value)

  nil
end

.normalize_hash(value) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/activejob/temporal/external_operation.rb', line 49

def normalize_hash(value)
  operation = payload_value(value, :temporal_operation)
  temporal_type = payload_value(value, :temporal_type)
  options = payload_value(value, :options) || {}

  new(operation, temporal_type, options).to_h
end

.payload_value(payload, key) ⇒ Object



57
58
59
# File 'lib/activejob/temporal/external_operation.rb', line 57

def payload_value(payload, key)
  payload[key] || payload[key.to_s]
end

.workflow(temporal_type, **options) ⇒ Object



17
18
19
# File 'lib/activejob/temporal/external_operation.rb', line 17

def self.workflow(temporal_type, **options)
  new(WORKFLOW, temporal_type, options)
end

Instance Method Details

#to_hObject



40
41
42
43
44
45
46
# File 'lib/activejob/temporal/external_operation.rb', line 40

def to_h
  {
    temporal_operation: operation,
    temporal_type: temporal_type,
    options: options.dup
  }
end