Parent

BackgrounDRb::MasterProxy

Attributes

reactor[RW]

(Not documented)

reloadable_workers[RW]

(Not documented)

worker_triggers[RW]

(Not documented)

Public Class Methods

new() click to toggle source

(Not documented)

    # File server/lib/master_proxy.rb, line 4
 4:     def initialize
 5:       raise "Running old Ruby version, upgrade to Ruby >= 1.8.5" unless check_for_ruby_version
 6: 
 7:       log_flag = BDRB_CONFIG[:backgroundrb][:debug_log].nil? ? true : BDRB_CONFIG[:backgroundrb][:debug_log]
 8:       debug_logger = DebugMaster.new(BDRB_CONFIG[:backgroundrb][:log],log_flag)
 9: 
10:       load_rails_env
11: 
12:       find_reloadable_worker
13: 
14:       Packet::Reactor.run do |t_reactor|
15:         @reactor = t_reactor
16:         t_reactor.start_worker(:worker => :log_worker,:worker_env => false) if log_flag
17:         t_reactor.start_server(BDRB_CONFIG[:backgroundrb][:ip],
18:                                BDRB_CONFIG[:backgroundrb][:port],MasterWorker) do |conn|
19:           conn.debug_logger = debug_logger
20:         end
21:         t_reactor.next_turn { reload_workers }
22:       end
23:     end

Public Instance Methods

check_for_ruby_version() click to toggle source

(Not documented)

     # File server/lib/master_proxy.rb, line 130
130:     def check_for_ruby_version; RUBY_VERSION >= "1.8.5"; end
find_reloadable_worker() click to toggle source

method should find reloadable workers and load their schedule from config file

    # File server/lib/master_proxy.rb, line 33
33:     def find_reloadable_worker
34:       t_workers = Dir["#{WORKER_ROOT}/**/*.rb"]
35:       @reloadable_workers = t_workers.map do |x|
36:         worker_name = File.basename(x,".rb")
37:         require worker_name
38:         worker_klass = Object.const_get(worker_name.classify)
39:         worker_klass.reload_flag ? worker_klass : nil
40:       end.compact
41:       @worker_triggers = { }
42:       @reloadable_workers.each do |t_worker|
43:         schedule = load_reloadable_schedule(t_worker)
44:         if schedule && !schedule.empty?
45:           @worker_triggers[t_worker.worker_name.to_sym] = schedule
46:         end
47:       end
48:     end
gen_worker_key(worker_name,worker_key = nil) click to toggle source

FIXME: Method by same name exists in Packet::NbioHelper module

    # File server/lib/master_proxy.rb, line 26
26:     def gen_worker_key(worker_name,worker_key = nil)
27:       return worker_name if worker_key.nil?
28:       return "#{worker_name}_#{worker_key}".to_sym
29:     end
load_and_invoke(worker_name,p_method,data) click to toggle source

method will load the worker and invoke worker method

     # File server/lib/master_proxy.rb, line 97
 97:     def load_and_invoke(worker_name,p_method,data)
 98:       begin
 99:         require worker_name.to_s
100:         worker_key = Packet::Guid.hexdigest
101:         @reactor.start_worker(:worker => worker_name,:worker_key => worker_key,:disable_log => true)
102:         worker_name_key = gen_worker_key(worker_name,worker_key)
103:         data_request = {:data => { :worker_method => p_method,:arg => data[:data]},
104:           :type => :request, :result => false
105:         }
106: 
107:         exit_request = {:data => { :worker_method => :exit},
108:           :type => :request, :result => false
109:         }
110:         t_worker = @reactor.live_workers[worker_name_key]
111:         if t_worker
112:           t_worker.send_request(data_request)
113:           t_worker.send_request(exit_request)
114:         end
115:       rescue LoadError
116:         puts "no such worker #{worker_name}"
117:       rescue MissingSourceFile
118:         puts "no such worker #{worker_name}"
119:         return
120:       end
121:     end
load_rails_env() click to toggle source

(Not documented)

     # File server/lib/master_proxy.rb, line 123
123:     def load_rails_env
124:       db_config_file = YAML.load(ERB.new(IO.read("#{RAILS_HOME}/config/database.yml")).result)
125:       run_env = ENV["RAILS_ENV"]
126:       ActiveRecord::Base.establish_connection(db_config_file[run_env])
127:       ActiveRecord::Base.allow_concurrency = true
128:     end
load_reloadable_schedule(t_worker) click to toggle source

load schedule of workers which should be restarted on schedule

    # File server/lib/master_proxy.rb, line 51
51:     def load_reloadable_schedule(t_worker)
52:       worker_method_triggers = { }
53:       all_schedules = BDRB_CONFIG[:schedules]
54:       return if all_schedules.nil? or all_schedules.empty?
55:       worker_schedule = all_schedules[t_worker.worker_name.to_sym]
56: 
57:       worker_schedule && worker_schedule.each do |key,value|
58:         case value[:trigger_args]
59:         when String
60:           cron_args = value[:trigger_args] || "0 0 0 0 0"
61:           trigger = BackgrounDRb::CronTrigger.new(cron_args)
62:           worker_method_triggers[key] = {
63:             :trigger => trigger,:data => value[:data],
64:             :runtime => trigger.fire_after_time(Time.now).to_i
65:           }
66:         when Hash
67:           trigger = BackgrounDRb::Trigger.new(value[:trigger_args])
68:           worker_method_triggers[key] = {
69:             :trigger => trigger,:data => value[:trigger_args][:data],
70:             :runtime => trigger.fire_after_time(Time.now).to_i
71:           }
72:         end
73:       end
74:       worker_method_triggers
75:     end
reload_workers() click to toggle source

Start the workers whose schedule has come

    # File server/lib/master_proxy.rb, line 78
78:     def reload_workers
79:       return if worker_triggers.empty?
80:       worker_triggers.each do |key,value|
81:         value.delete_if { |key,value| value[:trigger].respond_to?(:end_time) && value[:trigger].end_time <= Time.now }
82:       end
83: 
84:       worker_triggers.each do |worker_name,trigger|
85:         trigger.each do |key,value|
86:           time_now = Time.now.to_i
87:           if value[:runtime] < time_now
88:             load_and_invoke(worker_name,key,value)
89:             t_time = value[:trigger].fire_after_time(Time.now)
90:             value[:runtime] = t_time.to_i
91:           end
92:         end
93:       end
94:     end

secsequence

--- SEC00040

seccomment

--- ""

attributes

--- 
- name: reactor
  rw: RW
  a_desc: ""
- name: reloadable_workers
  rw: RW
  a_desc: ""
- name: worker_triggers
  rw: RW
  a_desc: ""

method_list

--- 
- methods: 
  - visibility: public
    aref: M000019
    name: new
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/master_proxy.rb, line 4</span>\n 4:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>\n 5:       <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-value str\">&quot;Running old Ruby version, upgrade to Ruby &gt;= 1.8.5&quot;</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">check_for_ruby_version</span>\n 6: \n 7:       <span class=\"ruby-identifier\">log_flag</span> = <span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:backgroundrb</span>][<span class=\"ruby-identifier\">:debug_log</span>].<span class=\"ruby-identifier\">nil?</span> <span class=\"ruby-value\">? </span><span class=\"ruby-keyword kw\">true</span> <span class=\"ruby-operator\">:</span> <span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:backgroundrb</span>][<span class=\"ruby-identifier\">:debug_log</span>]\n 8:       <span class=\"ruby-identifier\">debug_logger</span> = <span class=\"ruby-constant\">DebugMaster</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:backgroundrb</span>][<span class=\"ruby-identifier\">:log</span>],<span class=\"ruby-identifier\">log_flag</span>)\n 9: \n\
      10:       <span class=\"ruby-identifier\">load_rails_env</span>\n\
      11: \n\
      12:       <span class=\"ruby-identifier\">find_reloadable_worker</span>\n\
      13: \n\
      14:       <span class=\"ruby-constant\">Packet</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Reactor</span>.<span class=\"ruby-identifier\">run</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">t_reactor</span><span class=\"ruby-operator\">|</span>\n\
      15:         <span class=\"ruby-ivar\">@reactor</span> = <span class=\"ruby-identifier\">t_reactor</span>\n\
      16:         <span class=\"ruby-identifier\">t_reactor</span>.<span class=\"ruby-identifier\">start_worker</span>(<span class=\"ruby-identifier\">:worker</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">:log_worker</span>,<span class=\"ruby-identifier\">:worker_env</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-keyword kw\">false</span>) <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">log_flag</span>\n\
      17:         <span class=\"ruby-identifier\">t_reactor</span>.<span class=\"ruby-identifier\">start_server</span>(<span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:backgroundrb</span>][<span class=\"ruby-identifier\">:ip</span>],\n\
      18:                                <span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:backgroundrb</span>][<span class=\"ruby-identifier\">:port</span>],<span class=\"ruby-constant\">MasterWorker</span>) <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">conn</span><span class=\"ruby-operator\">|</span>\n\
      19:           <span class=\"ruby-identifier\">conn</span>.<span class=\"ruby-identifier\">debug_logger</span> = <span class=\"ruby-identifier\">debug_logger</span>\n\
      20:         <span class=\"ruby-keyword kw\">end</span>\n\
      21:         <span class=\"ruby-identifier\">t_reactor</span>.<span class=\"ruby-identifier\">next_turn</span> { <span class=\"ruby-identifier\">reload_workers</span> }\n\
      22:       <span class=\"ruby-keyword kw\">end</span>\n\
      23:     <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  category: Class
  type: Public
- methods: 
  - visibility: public
    aref: M000026
    name: check_for_ruby_version
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/master_proxy.rb, line 130</span>\n\
      130:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">check_for_ruby_version</span>; <span class=\"ruby-constant\">RUBY_VERSION</span> <span class=\"ruby-operator\">&gt;=</span> <span class=\"ruby-value str\">&quot;1.8.5&quot;</span>; <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  - visibility: public
    aref: M000021
    name: find_reloadable_worker
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/master_proxy.rb, line 33</span>\n\
      33:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">find_reloadable_worker</span>\n\
      34:       <span class=\"ruby-identifier\">t_workers</span> = <span class=\"ruby-constant\">Dir</span>[<span class=\"ruby-node\">&quot;#{WORKER_ROOT}/**/*.rb&quot;</span>]\n\
      35:       <span class=\"ruby-ivar\">@reloadable_workers</span> = <span class=\"ruby-identifier\">t_workers</span>.<span class=\"ruby-identifier\">map</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">x</span><span class=\"ruby-operator\">|</span>\n\
      36:         <span class=\"ruby-identifier\">worker_name</span> = <span class=\"ruby-constant\">File</span>.<span class=\"ruby-identifier\">basename</span>(<span class=\"ruby-identifier\">x</span>,<span class=\"ruby-value str\">&quot;.rb&quot;</span>)\n\
      37:         <span class=\"ruby-identifier\">require</span> <span class=\"ruby-identifier\">worker_name</span>\n\
      38:         <span class=\"ruby-identifier\">worker_klass</span> = <span class=\"ruby-constant\">Object</span>.<span class=\"ruby-identifier\">const_get</span>(<span class=\"ruby-identifier\">worker_name</span>.<span class=\"ruby-identifier\">classify</span>)\n\
      39:         <span class=\"ruby-identifier\">worker_klass</span>.<span class=\"ruby-identifier\">reload_flag</span> <span class=\"ruby-value\">? </span><span class=\"ruby-identifier\">worker_klass</span> <span class=\"ruby-operator\">:</span> <span class=\"ruby-keyword kw\">nil</span>\n\
      40:       <span class=\"ruby-keyword kw\">end</span>.<span class=\"ruby-identifier\">compact</span>\n\
      41:       <span class=\"ruby-ivar\">@worker_triggers</span> = { }\n\
      42:       <span class=\"ruby-ivar\">@reloadable_workers</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">t_worker</span><span class=\"ruby-operator\">|</span>\n\
      43:         <span class=\"ruby-identifier\">schedule</span> = <span class=\"ruby-identifier\">load_reloadable_schedule</span>(<span class=\"ruby-identifier\">t_worker</span>)\n\
      44:         <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">schedule</span> <span class=\"ruby-operator\">&amp;&amp;</span> <span class=\"ruby-operator\">!</span><span class=\"ruby-identifier\">schedule</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      45:           <span class=\"ruby-ivar\">@worker_triggers</span>[<span class=\"ruby-identifier\">t_worker</span>.<span class=\"ruby-identifier\">worker_name</span>.<span class=\"ruby-identifier\">to_sym</span>] = <span class=\"ruby-identifier\">schedule</span>\n\
      46:         <span class=\"ruby-keyword kw\">end</span>\n\
      47:       <span class=\"ruby-keyword kw\">end</span>\n\
      48:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      method should find reloadable workers and load their schedule from config
      file
      </p>
    params: ()
  - visibility: public
    aref: M000020
    name: gen_worker_key
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/master_proxy.rb, line 26</span>\n\
      26:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">gen_worker_key</span>(<span class=\"ruby-identifier\">worker_name</span>,<span class=\"ruby-identifier\">worker_key</span> = <span class=\"ruby-keyword kw\">nil</span>)\n\
      27:       <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">worker_name</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">worker_key</span>.<span class=\"ruby-identifier\">nil?</span>\n\
      28:       <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-node\">&quot;#{worker_name}_#{worker_key}&quot;</span>.<span class=\"ruby-identifier\">to_sym</span>\n\
      29:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      FIXME: Method by same name exists in Packet::NbioHelper module
      </p>
    params: (worker_name,worker_key = nil)
  - visibility: public
    aref: M000024
    name: load_and_invoke
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/master_proxy.rb, line 97</span>\n 97:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">load_and_invoke</span>(<span class=\"ruby-identifier\">worker_name</span>,<span class=\"ruby-identifier\">p_method</span>,<span class=\"ruby-identifier\">data</span>)\n 98:       <span class=\"ruby-keyword kw\">begin</span>\n 99:         <span class=\"ruby-identifier\">require</span> <span class=\"ruby-identifier\">worker_name</span>.<span class=\"ruby-identifier\">to_s</span>\n\
      100:         <span class=\"ruby-identifier\">worker_key</span> = <span class=\"ruby-constant\">Packet</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Guid</span>.<span class=\"ruby-identifier\">hexdigest</span>\n\
      101:         <span class=\"ruby-ivar\">@reactor</span>.<span class=\"ruby-identifier\">start_worker</span>(<span class=\"ruby-identifier\">:worker</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">worker_name</span>,<span class=\"ruby-identifier\">:worker_key</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">worker_key</span>,<span class=\"ruby-identifier\">:disable_log</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-keyword kw\">true</span>)\n\
      102:         <span class=\"ruby-identifier\">worker_name_key</span> = <span class=\"ruby-identifier\">gen_worker_key</span>(<span class=\"ruby-identifier\">worker_name</span>,<span class=\"ruby-identifier\">worker_key</span>)\n\
      103:         <span class=\"ruby-identifier\">data_request</span> = {<span class=\"ruby-identifier\">:data</span> =<span class=\"ruby-operator\">&gt;</span> { <span class=\"ruby-identifier\">:worker_method</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">p_method</span>,<span class=\"ruby-identifier\">:arg</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">data</span>[<span class=\"ruby-identifier\">:data</span>]},\n\
      104:           <span class=\"ruby-identifier\">:type</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">:request</span>, <span class=\"ruby-identifier\">:result</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-keyword kw\">false</span>\n\
      105:         }\n\
      106: \n\
      107:         <span class=\"ruby-identifier\">exit_request</span> = {<span class=\"ruby-identifier\">:data</span> =<span class=\"ruby-operator\">&gt;</span> { <span class=\"ruby-identifier\">:worker_method</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">:exit</span>},\n\
      108:           <span class=\"ruby-identifier\">:type</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">:request</span>, <span class=\"ruby-identifier\">:result</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-keyword kw\">false</span>\n\
      109:         }\n\
      110:         <span class=\"ruby-identifier\">t_worker</span> = <span class=\"ruby-ivar\">@reactor</span>.<span class=\"ruby-identifier\">live_workers</span>[<span class=\"ruby-identifier\">worker_name_key</span>]\n\
      111:         <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">t_worker</span>\n\
      112:           <span class=\"ruby-identifier\">t_worker</span>.<span class=\"ruby-identifier\">send_request</span>(<span class=\"ruby-identifier\">data_request</span>)\n\
      113:           <span class=\"ruby-identifier\">t_worker</span>.<span class=\"ruby-identifier\">send_request</span>(<span class=\"ruby-identifier\">exit_request</span>)\n\
      114:         <span class=\"ruby-keyword kw\">end</span>\n\
      115:       <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">LoadError</span>\n\
      116:         <span class=\"ruby-identifier\">puts</span> <span class=\"ruby-node\">&quot;no such worker #{worker_name}&quot;</span>\n\
      117:       <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">MissingSourceFile</span>\n\
      118:         <span class=\"ruby-identifier\">puts</span> <span class=\"ruby-node\">&quot;no such worker #{worker_name}&quot;</span>\n\
      119:         <span class=\"ruby-keyword kw\">return</span>\n\
      120:       <span class=\"ruby-keyword kw\">end</span>\n\
      121:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      method will load the worker and invoke worker method
      </p>
    params: (worker_name,p_method,data)
  - visibility: public
    aref: M000025
    name: load_rails_env
    sourcecode: "     <span class=\"ruby-comment cmt\"># File server/lib/master_proxy.rb, line 123</span>\n\
      123:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">load_rails_env</span>\n\
      124:       <span class=\"ruby-identifier\">db_config_file</span> = <span class=\"ruby-constant\">YAML</span>.<span class=\"ruby-identifier\">load</span>(<span class=\"ruby-constant\">ERB</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-constant\">IO</span>.<span class=\"ruby-identifier\">read</span>(<span class=\"ruby-node\">&quot;#{RAILS_HOME}/config/database.yml&quot;</span>)).<span class=\"ruby-identifier\">result</span>)\n\
      125:       <span class=\"ruby-identifier\">run_env</span> = <span class=\"ruby-constant\">ENV</span>[<span class=\"ruby-value str\">&quot;RAILS_ENV&quot;</span>]\n\
      126:       <span class=\"ruby-constant\">ActiveRecord</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Base</span>.<span class=\"ruby-identifier\">establish_connection</span>(<span class=\"ruby-identifier\">db_config_file</span>[<span class=\"ruby-identifier\">run_env</span>])\n\
      127:       <span class=\"ruby-constant\">ActiveRecord</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Base</span>.<span class=\"ruby-identifier\">allow_concurrency</span> = <span class=\"ruby-keyword kw\">true</span>\n\
      128:     <span class=\"ruby-keyword kw\">end</span>"
    params: ()
  - visibility: public
    aref: M000022
    name: load_reloadable_schedule
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/master_proxy.rb, line 51</span>\n\
      51:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">load_reloadable_schedule</span>(<span class=\"ruby-identifier\">t_worker</span>)\n\
      52:       <span class=\"ruby-identifier\">worker_method_triggers</span> = { }\n\
      53:       <span class=\"ruby-identifier\">all_schedules</span> = <span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:schedules</span>]\n\
      54:       <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">all_schedules</span>.<span class=\"ruby-identifier\">nil?</span> <span class=\"ruby-keyword kw\">or</span> <span class=\"ruby-identifier\">all_schedules</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      55:       <span class=\"ruby-identifier\">worker_schedule</span> = <span class=\"ruby-identifier\">all_schedules</span>[<span class=\"ruby-identifier\">t_worker</span>.<span class=\"ruby-identifier\">worker_name</span>.<span class=\"ruby-identifier\">to_sym</span>]\n\
      56: \n\
      57:       <span class=\"ruby-identifier\">worker_schedule</span> <span class=\"ruby-operator\">&amp;&amp;</span> <span class=\"ruby-identifier\">worker_schedule</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">key</span>,<span class=\"ruby-identifier\">value</span><span class=\"ruby-operator\">|</span>\n\
      58:         <span class=\"ruby-keyword kw\">case</span> <span class=\"ruby-identifier\">value</span>[<span class=\"ruby-identifier\">:trigger_args</span>]\n\
      59:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">String</span>\n\
      60:           <span class=\"ruby-identifier\">cron_args</span> = <span class=\"ruby-identifier\">value</span>[<span class=\"ruby-identifier\">:trigger_args</span>] <span class=\"ruby-operator\">||</span> <span class=\"ruby-value str\">&quot;0 0 0 0 0&quot;</span>\n\
      61:           <span class=\"ruby-identifier\">trigger</span> = <span class=\"ruby-constant\">BackgrounDRb</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">CronTrigger</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-identifier\">cron_args</span>)\n\
      62:           <span class=\"ruby-identifier\">worker_method_triggers</span>[<span class=\"ruby-identifier\">key</span>] = {\n\
      63:             <span class=\"ruby-identifier\">:trigger</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">trigger</span>,<span class=\"ruby-identifier\">:data</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">value</span>[<span class=\"ruby-identifier\">:data</span>],\n\
      64:             <span class=\"ruby-identifier\">:runtime</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">trigger</span>.<span class=\"ruby-identifier\">fire_after_time</span>(<span class=\"ruby-constant\">Time</span>.<span class=\"ruby-identifier\">now</span>).<span class=\"ruby-identifier\">to_i</span>\n\
      65:           }\n\
      66:         <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">Hash</span>\n\
      67:           <span class=\"ruby-identifier\">trigger</span> = <span class=\"ruby-constant\">BackgrounDRb</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Trigger</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-identifier\">value</span>[<span class=\"ruby-identifier\">:trigger_args</span>])\n\
      68:           <span class=\"ruby-identifier\">worker_method_triggers</span>[<span class=\"ruby-identifier\">key</span>] = {\n\
      69:             <span class=\"ruby-identifier\">:trigger</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">trigger</span>,<span class=\"ruby-identifier\">:data</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">value</span>[<span class=\"ruby-identifier\">:trigger_args</span>][<span class=\"ruby-identifier\">:data</span>],\n\
      70:             <span class=\"ruby-identifier\">:runtime</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">trigger</span>.<span class=\"ruby-identifier\">fire_after_time</span>(<span class=\"ruby-constant\">Time</span>.<span class=\"ruby-identifier\">now</span>).<span class=\"ruby-identifier\">to_i</span>\n\
      71:           }\n\
      72:         <span class=\"ruby-keyword kw\">end</span>\n\
      73:       <span class=\"ruby-keyword kw\">end</span>\n\
      74:       <span class=\"ruby-identifier\">worker_method_triggers</span>\n\
      75:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      load schedule of workers which should be restarted on schedule
      </p>
    params: (t_worker)
  - visibility: public
    aref: M000023
    name: reload_workers
    sourcecode: "    <span class=\"ruby-comment cmt\"># File server/lib/master_proxy.rb, line 78</span>\n\
      78:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">reload_workers</span>\n\
      79:       <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">worker_triggers</span>.<span class=\"ruby-identifier\">empty?</span>\n\
      80:       <span class=\"ruby-identifier\">worker_triggers</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">key</span>,<span class=\"ruby-identifier\">value</span><span class=\"ruby-operator\">|</span>\n\
      81:         <span class=\"ruby-identifier\">value</span>.<span class=\"ruby-identifier\">delete_if</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">key</span>,<span class=\"ruby-identifier\">value</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">value</span>[<span class=\"ruby-identifier\">:trigger</span>].<span class=\"ruby-identifier\">respond_to?</span>(<span class=\"ruby-identifier\">:end_time</span>) <span class=\"ruby-operator\">&amp;&amp;</span> <span class=\"ruby-identifier\">value</span>[<span class=\"ruby-identifier\">:trigger</span>].<span class=\"ruby-identifier\">end_time</span> <span class=\"ruby-operator\">&lt;=</span> <span class=\"ruby-constant\">Time</span>.<span class=\"ruby-identifier\">now</span> }\n\
      82:       <span class=\"ruby-keyword kw\">end</span>\n\
      83: \n\
      84:       <span class=\"ruby-identifier\">worker_triggers</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">worker_name</span>,<span class=\"ruby-identifier\">trigger</span><span class=\"ruby-operator\">|</span>\n\
      85:         <span class=\"ruby-identifier\">trigger</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">key</span>,<span class=\"ruby-identifier\">value</span><span class=\"ruby-operator\">|</span>\n\
      86:           <span class=\"ruby-identifier\">time_now</span> = <span class=\"ruby-constant\">Time</span>.<span class=\"ruby-identifier\">now</span>.<span class=\"ruby-identifier\">to_i</span>\n\
      87:           <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">value</span>[<span class=\"ruby-identifier\">:runtime</span>] <span class=\"ruby-operator\">&lt;</span> <span class=\"ruby-identifier\">time_now</span>\n\
      88:             <span class=\"ruby-identifier\">load_and_invoke</span>(<span class=\"ruby-identifier\">worker_name</span>,<span class=\"ruby-identifier\">key</span>,<span class=\"ruby-identifier\">value</span>)\n\
      89:             <span class=\"ruby-identifier\">t_time</span> = <span class=\"ruby-identifier\">value</span>[<span class=\"ruby-identifier\">:trigger</span>].<span class=\"ruby-identifier\">fire_after_time</span>(<span class=\"ruby-constant\">Time</span>.<span class=\"ruby-identifier\">now</span>)\n\
      90:             <span class=\"ruby-identifier\">value</span>[<span class=\"ruby-identifier\">:runtime</span>] = <span class=\"ruby-identifier\">t_time</span>.<span class=\"ruby-identifier\">to_i</span>\n\
      91:           <span class=\"ruby-keyword kw\">end</span>\n\
      92:         <span class=\"ruby-keyword kw\">end</span>\n\
      93:       <span class=\"ruby-keyword kw\">end</span>\n\
      94:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Start the workers whose schedule has come
      </p>
    params: ()
  category: Instance
  type: Public

sectitle

--- 

[Validate]

Generated with the Darkfish Rdoc Generator.