Module: CPEE::Message
- Defined in:
- lib/cpee/message.rb
Constant Summary collapse
- WHO =
'cpee'
- TYPE =
'instance'
Class Method Summary collapse
- .send(type, event, cpee, instance, instance_uuid, instance_name, content = {}, backend = nil) ⇒ Object
- .send_url(type, event, cpee, content = {}, backend) ⇒ Object
- .set_workers(workers) ⇒ Object
- .target ⇒ Object
Class Method Details
.send(type, event, cpee, instance, instance_uuid, instance_name, content = {}, backend = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cpee/message.rb', line 30 def self::send(type, event, cpee, instance, instance_uuid, instance_name, content={}, backend=nil) target = '%02i' % 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(3), '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 + ' ' + JSON::generate(payload) ) end |
.send_url(type, event, cpee, content = {}, backend) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cpee/message.rb', line 53 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
21 22 23 24 |
# File 'lib/cpee/message.rb', line 21 def self::set_workers(workers) @@tworkers = (workers < 1 && workers > 99 ? 1 : workers).freeze @@last = -1 end |
.target ⇒ Object
26 27 28 |
# File 'lib/cpee/message.rb', line 26 def self::target @@last < @@tworkers-1 ? @@last += 1 : @@last = 0 end |