Class: CPEE::Worklist::Controller
- Inherits:
-
Object
- Object
- CPEE::Worklist::Controller
- Defined in:
- lib/cpee-worklist/controller.rb
Instance Attribute Summary collapse
-
#activities ⇒ Object
readonly
Returns the value of attribute activities.
-
#callback_keys ⇒ Object
readonly
Returns the value of attribute callback_keys.
-
#communication ⇒ Object
readonly
Returns the value of attribute communication.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#notifications ⇒ Object
readonly
Returns the value of attribute notifications.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#orgmodels ⇒ Object
readonly
Returns the value of attribute orgmodels.
-
#votes ⇒ Object
readonly
Returns the value of attribute votes.
Instance Method Summary collapse
- #add_activity(activity) ⇒ Object
-
#add_orgmodel(name, content) ⇒ Object
{{{.
- #base ⇒ Object
- #base_url ⇒ Object
- #callback(hw, key, content) ⇒ Object
- #cancel_callback(key) ⇒ Object
- #host ⇒ Object
- #id ⇒ Object
- #info ⇒ Object
-
#initialize(opts) ⇒ Controller
constructor
A new instance of Controller.
- #instance_id ⇒ Object
- #instance_url ⇒ Object
-
#notify(what, content = {}) ⇒ Object
}}}.
- #uuid ⇒ Object
- #vote(what, content = {}) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Controller
Returns a new instance of Controller.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cpee-worklist/controller.rb', line 26 def initialize(opts) CPEE::redis_connect(opts,"Main") @opts = opts @redis = opts[:redis] @votes = [] @activities = Activities.new(opts) @activities.unserialize CPEE::Persistence::new_static_object(CPEE::Persistence::obj,opts) @orgmodels = [] Dir::glob(File.join(@opts[:top],'orgmodels','*')).each do |g| add_orgmodel File.basename(g), File.read(g) end @callback_keys = {} @psredis = @opts[:redis_dyn].call "Callback Response" Thread.new do @psredis.psubscribe('callback-response:*','callback-end:*') do |on| on. do |pat, what, | if pat == 'callback-response:*' && @callback_keys.has_key?(what[18..-1]) index = .index(' ') mess = [index+1..-1] instance = [0...index] m = JSON.parse(mess) resp = [] m['content']['values'].each do |e| if e[1][0] == 'simple' resp << Riddl::Parameter::Simple.new(e[0],e[1][1]) elsif e[1][0] == 'complex' resp << Riddl::Parameter::Complex.new(e[0],e[1][1],File.open(e[1][2])) end end @callback_keys[what[18..-1]].send(:callback,resp,m['content']['headers']) end if pat == 'callback-end:*' @callback_keys.delete(what[13..-1]) end end end end end |
Instance Attribute Details
#activities ⇒ Object (readonly)
Returns the value of attribute activities.
24 25 26 |
# File 'lib/cpee-worklist/controller.rb', line 24 def activities @activities end |
#callback_keys ⇒ Object (readonly)
Returns the value of attribute callback_keys.
24 25 26 |
# File 'lib/cpee-worklist/controller.rb', line 24 def callback_keys @callback_keys end |
#communication ⇒ Object (readonly)
Returns the value of attribute communication.
24 25 26 |
# File 'lib/cpee-worklist/controller.rb', line 24 def communication @communication end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
24 25 26 |
# File 'lib/cpee-worklist/controller.rb', line 24 def events @events end |
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
24 25 26 |
# File 'lib/cpee-worklist/controller.rb', line 24 def notifications @notifications end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
24 25 26 |
# File 'lib/cpee-worklist/controller.rb', line 24 def opts @opts end |
#orgmodels ⇒ Object (readonly)
Returns the value of attribute orgmodels.
24 25 26 |
# File 'lib/cpee-worklist/controller.rb', line 24 def orgmodels @orgmodels end |
#votes ⇒ Object (readonly)
Returns the value of attribute votes.
24 25 26 |
# File 'lib/cpee-worklist/controller.rb', line 24 def votes @votes end |
Instance Method Details
#add_activity(activity) ⇒ Object
152 153 154 155 |
# File 'lib/cpee-worklist/controller.rb', line 152 def add_activity(activity) @activities << activity @activities.serialize end |
#add_orgmodel(name, content) ⇒ Object
{{{
98 99 100 101 102 |
# File 'lib/cpee-worklist/controller.rb', line 98 def add_orgmodel(name,content) #{{{ FileUtils.mkdir_p(File.join(@opts[:top],'orgmodels')) @orgmodels << name unless @orgmodels.include?(name) File.write(File.join(@opts[:top],'orgmodels',name), content) end |
#base ⇒ Object
90 91 92 |
# File 'lib/cpee-worklist/controller.rb', line 90 def base base_url end |
#base_url ⇒ Object
81 82 83 |
# File 'lib/cpee-worklist/controller.rb', line 81 def base_url File.join(@opts[:url],'/') end |
#callback(hw, key, content) ⇒ Object
143 144 145 146 |
# File 'lib/cpee-worklist/controller.rb', line 143 def callback(hw,key,content) CPEE::Message::send(:callback,'activity/content',base,info,uuid,info,content.merge(:key => key),@redis) @callback_keys[key] = hw end |
#cancel_callback(key) ⇒ Object
148 149 150 |
# File 'lib/cpee-worklist/controller.rb', line 148 def cancel_callback(key) CPEE::Message::send(:'callback-end',key,base,info,uuid,info,{},@redis) end |
#host ⇒ Object
78 79 80 |
# File 'lib/cpee-worklist/controller.rb', line 78 def host @opts[:host] end |
#id ⇒ Object
72 73 74 |
# File 'lib/cpee-worklist/controller.rb', line 72 def id 'worklist' end |
#info ⇒ Object
94 95 96 |
# File 'lib/cpee-worklist/controller.rb', line 94 def info 'worklist' end |
#instance_id ⇒ Object
87 88 89 |
# File 'lib/cpee-worklist/controller.rb', line 87 def instance_id @id end |
#instance_url ⇒ Object
84 85 86 |
# File 'lib/cpee-worklist/controller.rb', line 84 def instance_url File.join(@opts[:url].to_s,'/') end |
#notify(what, content = {}) ⇒ Object
}}}
104 105 106 |
# File 'lib/cpee-worklist/controller.rb', line 104 def notify(what,content={}) CPEE::Message::send(:event,what,base,info,uuid,info,content,@redis) end |
#uuid ⇒ Object
75 76 77 |
# File 'lib/cpee-worklist/controller.rb', line 75 def uuid @id end |
#vote(what, content = {}) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/cpee-worklist/controller.rb', line 108 def vote(what,content={}) topic, name = what.split('/') handler = File.join(topic,'vote',name) votes = [] CPEE::Persistence::extract_handler(id,@opts,handler).each do |client| voteid = Digest::MD5.hexdigest(Kernel::rand().to_s) content[:key] = voteid content[:subscription] = client votes << voteid CPEE::Message::send(:vote,what,base,info,uuid,info,content,@redis) end if votes.length > 0 @votes += votes psredis = @opts[:redis_dyn].call "Vote" collect = [] psredis.subscribe(votes.map{|e| ['vote-response:' + e.to_s] }.flatten) do |on| on. do |what, | index = .index(' ') mess = [index+1..-1] m = JSON.parse(mess) collect << ((m['content'] == true || m['content'] == 'true') || false) @votes.delete m['name'] cancel_callback m['name'] if collect.length >= votes.length psredis.unsubscribe end end end !collect.include?(false) else true end end |