module CPEE::Message
Public Class Methods
Source
# File lib/cpee/message.rb, line 62 def self::send(type, event, cpee, instance, instance_uuid, instance_name, content={}, backend=nil, tt=nil) target = '%02i' % (tt || CPEE::Message::target) topic = ::File::dirname(event) name = ::File::basename(event) payload = { @@who => cpee, @@type + '-url' => File.join(cpee,instance.to_s), @@type => instance, 'topic' => topic, 'type' => type, 'name' => name, 'timestamp' => Time.now.xmlschema(6), 'content' => content } payload[@@type + '-uuid'] = instance_uuid if instance_uuid payload[@@type + '-name'] = instance_name if instance_name backend.publish(type.to_s + ':' + target + ':' + event.to_s, instance.to_s + ',' + instance_uuid.to_s + ' ' + JSON::generate(payload) ) end
Source
# File lib/cpee/message.rb, line 85 def self::send_url(type, event, cpee, content={}, backend) EM.defer do topic = ::File::dirname(event) name = ::File::basename(event) payload = { @@who => cpee, 'topic' => topic, 'type' => type, 'name' => name, 'timestamp' => Time.now.xmlschema(3), 'content' => content } client = Riddl::Client.new(backend) client.post [ Riddl::Parameter::Simple::new('type',type), Riddl::Parameter::Simple::new('topic',topic), Riddl::Parameter::Simple::new('event',name), Riddl::Parameter::Complex::new('notification','application/json',JSON::generate(payload)) ] end end
Source
# File lib/cpee/message.rb, line 36 def self::set_workers(workers) @@tworkers = (workers < 1 && workers > 99 ? 1 : workers).freeze @@last = -1 end
Source
# File lib/cpee/message.rb, line 41 def self::target @@last < @@tworkers-1 ? @@last += 1 : @@last = 0 end
Source
# File lib/cpee/message.rb, line 45 def self::wait(backend,sub,tt=nil) target = '%02i' % (tt || CPEE::Message::target) wid = Digest::MD5.hexdigest(Kernel::rand().to_s) begin sub.subscribe_with_timeout(2,'event:' + target + ':transaction/finished') do |on| on.message do |what,message| mess = message[0...message.index(' ')] sub.unsubscribe('event:' + target + ':transaction/finished') if mess == wid end backend.publish('event:' + target + ':transaction/start',wid + ' {}') end rescue => e puts "timeout error" end sub.disconnect! end