Class: Factor::Runtime::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/runtime/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessage

Returns a new instance of Message.



8
9
10
11
12
13
# File 'lib/runtime/message.rb', line 8

def initialize
  @activity_instance_id=SecureRandom.hex
  @workflow = workflow
  @body = Hash.new
  @position = Array.new
end

Instance Attribute Details

#activity_instance_idObject

Returns the value of attribute activity_instance_id.



7
8
9
# File 'lib/runtime/message.rb', line 7

def activity_instance_id
  @activity_instance_id
end

#bodyObject

Returns the value of attribute body.



7
8
9
# File 'lib/runtime/message.rb', line 7

def body
  @body
end

#last_activity_instance_idObject

Returns the value of attribute last_activity_instance_id.



7
8
9
# File 'lib/runtime/message.rb', line 7

def last_activity_instance_id
  @last_activity_instance_id
end

#positionObject

Returns the value of attribute position.



7
8
9
# File 'lib/runtime/message.rb', line 7

def position
  @position
end

#workflowObject

Returns the value of attribute workflow.



7
8
9
# File 'lib/runtime/message.rb', line 7

def workflow
  @workflow
end

#workflow_instance_idObject

Returns the value of attribute workflow_instance_id.



7
8
9
# File 'lib/runtime/message.rb', line 7

def workflow_instance_id
  @workflow_instance_id
end

Instance Method Details

#add_values(values) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/runtime/message.rb', line 29

def add_values(values)
  current=@body
  position.each do |key|
    #puts "[add value] #{key} (#{key.class.name})"
    current[key]={} if !current.include?(key)
    current=current[key]
  end
  values.each do |key,value|
    current[key]=value
  end

end

#from_queue(routing_key, payload) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/runtime/message.rb', line 50

def from_queue routing_key, payload
  routing_array=routing_key.split('.')
  @workflow=routing_array.first #first
  @position=routing_array.drop(1) # everything after first

  message=JSON.parse(payload)
  @body=message["body"]
  @workflow_instance_id=message["workflow_instance_id"]
  @activity_instance_id=message["activity_instance_id"]
  @last_activity_instance_id=message["last_activity_instance_id"]
end

#payloadObject



46
47
48
# File 'lib/runtime/message.rb', line 46

def payload
  {"body"=>@body, "workflow_instance_id"=>@workflow_instance_id, "activity_instance_id"=>@activity_instance_id, "last_activity_instance_id"=>@last_activity_instance_id}.to_json
end

#respond(params, event) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/runtime/message.rb', line 15

def respond(params, event)
  m = Message.new
  m.body = @body
  m.workflow_instance_id=@workflow_instance_id
  m.last_activity_instance_id = @activity_instance_id
  m.workflow = @workflow
  m.position = @position
  m.position << "on"
  m.position << event
  m.add_values(params)
  m
end

#routeObject



42
43
44
# File 'lib/runtime/message.rb', line 42

def route
  "#{workflow}.#{position.join('.')}"
end