Sha256: 30c084385a834b0fb40e79478e8962ef08f49e40929c3afe67c1c2af8506f8af
Contents?: true
Size: 1.84 KB
Versions: 6
Compression:
Stored size: 1.84 KB
Contents
require 'rubygems' require 'SecureRandom' require 'json' module Factor module Runtime class Message attr_accessor :body, :workflow, :workflow_instance_id, :activity_instance_id, :last_activity_instance_id, :position def initialize @activity_instance_id=SecureRandom.hex @workflow = workflow @body = Hash.new @position = Array.new end 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 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 def route "#{workflow}.#{position.join('.')}" end 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 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 end end end
Version data entries
6 entries across 6 versions & 1 rubygems