Module: CPEE::Message
- Defined in:
- lib/cpee/message.rb
Constant Summary collapse
- @@who =
'cpee'
- @@type =
'instance'
- @@tworkers =
1
- @@last =
-1
Class Method Summary collapse
- .send(type, event, cpee, instance, instance_uuid, instance_name, content = {}, backend = nil, tt = nil) ⇒ Object
- .send_url(type, event, cpee, content = {}, backend) ⇒ Object
-
.set_workers(workers) ⇒ Object
}}}.
- .target ⇒ Object
-
.type ⇒ Object
}}}.
-
.type=(it) ⇒ Object
}}}.
- .wait(backend, sub, tt = nil) ⇒ Object
-
.who ⇒ Object
{{{.
-
.who=(it) ⇒ Object
}}}.
Class Method Details
.send(type, event, cpee, instance, instance_uuid, instance_name, content = {}, backend = nil, tt = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# 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 |
.send_url(type, event, cpee, content = {}, backend) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# 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 |
.set_workers(workers) ⇒ Object
}}}
36 37 38 39 |
# File 'lib/cpee/message.rb', line 36 def self::set_workers(workers) @@tworkers = (workers < 1 && workers > 99 ? 1 : workers).freeze @@last = -1 end |
.target ⇒ Object
41 42 43 |
# File 'lib/cpee/message.rb', line 41 def self::target @@last < @@tworkers-1 ? @@last += 1 : @@last = 0 end |
.type ⇒ Object
}}}
29 30 31 |
# File 'lib/cpee/message.rb', line 29 def self::type #{{{ @@type end |
.type=(it) ⇒ Object
}}}
32 33 34 |
# File 'lib/cpee/message.rb', line 32 def self::type=(it) #{{{ @@type = it end |
.wait(backend, sub, tt = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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. do |what,| mess = [0....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 |
.who ⇒ Object
{{{
23 24 25 |
# File 'lib/cpee/message.rb', line 23 def self::who #{{{ @@who end |
.who=(it) ⇒ Object
}}}
26 27 28 |
# File 'lib/cpee/message.rb', line 26 def self::who=(it) #{{{ @@who = it end |