Parent

BackgrounDRb::RailsWorkerProxy

A Worker proxy, which uses method_missing for delegating method calls to the workers

Attributes

data[RW]

(Not documented)

middle_man[RW]

(Not documented)

worker_key[RW]

(Not documented)

worker_method[RW]

(Not documented)

worker_name[RW]

(Not documented)

Public Class Methods

new(p_worker_name,p_worker_key = nil,p_middle_man = nil) click to toggle source

create new worker proxy

    # File lib/backgroundrb/rails_worker_proxy.rb, line 7
 7:     def initialize(p_worker_name,p_worker_key = nil,p_middle_man = nil)
 8:       @worker_name = p_worker_name
 9:       @middle_man = p_middle_man
10:       @worker_key = p_worker_key
11:       @tried_connections = []
12:     end

Public Instance Methods

ask_result(job_key) click to toggle source

get results back from the cache. Cache can be in-memory worker cache or memcache based cache

    # File lib/backgroundrb/rails_worker_proxy.rb, line 91
91:     def ask_result job_key
92:       options = compact(:worker => worker_name,:worker_key => worker_key,:job_key => job_key)
93:       if BDRB_CONFIG[:backgroundrb][:result_storage] == 'memcache'
94:         return_result_from_memcache(options)
95:       else
96:         result = middle_man.backend_connections.map { |conn| conn.ask_result(options) }
97:         return_result(result)
98:       end
99:     end
choose_connection(host_info) click to toggle source

choose a worker

     # File lib/backgroundrb/rails_worker_proxy.rb, line 142
142:     def choose_connection host_info
143:       case host_info
144:       when :all; middle_man.backend_connections
145:       when :local; middle_man.find_local
146:       when String; middle_man.find_connection(host_info)
147:       else; middle_man.choose_server
148:       end
149:     end
compact(options = { }) click to toggle source

helper method to compact a hash and for getting rid of nil parameters

     # File lib/backgroundrb/rails_worker_proxy.rb, line 152
152:     def compact(options = { })
153:       options.delete_if { |key,value| value.nil? }
154:       options
155:     end
delete() click to toggle source

delete a worker

     # File lib/backgroundrb/rails_worker_proxy.rb, line 134
134:     def delete
135:       middle_man.backend_connections.each do |connection|
136:         connection.delete_worker(compact(:worker => worker_name, :worker_key => worker_key))
137:       end
138:       return worker_key
139:     end
dequeue_task(options = {}) click to toggle source

remove tasks from the worker pool

    # File lib/backgroundrb/rails_worker_proxy.rb, line 51
51:     def dequeue_task options = {}
52:       BdrbJobQueue.remove_job(options)
53:     end
enqueue_task(options = {}) click to toggle source

enqueue tasks to the worker pool

    # File lib/backgroundrb/rails_worker_proxy.rb, line 46
46:     def enqueue_task options = {}
47:       BdrbJobQueue.insert_job(options)
48:     end
gen_key(options) click to toggle source

generate worker key

     # File lib/backgroundrb/rails_worker_proxy.rb, line 109
109:     def gen_key options
110:       key = [options[:worker],options[:worker_key],options[:job_key]].compact.join('_')
111:       key
112:     end
invoke_on_connection(connection,method_name,options = {}) click to toggle source

choose a backgroundrb server connection and invoke worker method on it.

    # File lib/backgroundrb/rails_worker_proxy.rb, line 84
84:     def invoke_on_connection connection,method_name,options = {}
85:       raise NoServerAvailable.new("No BackgrounDRb is found running") unless connection
86:       connection.send(method_name,options)
87:     end
method_missing(method_id,*args) click to toggle source

(Not documented)

    # File lib/backgroundrb/rails_worker_proxy.rb, line 14
14:     def method_missing(method_id,*args)
15:       worker_method = method_id.to_s
16:       arguments = args.first
17: 
18:       arg,job_key,host_info,scheduled_at = arguments && arguments.values_at(:arg,:job_key,:host,:scheduled_at)
19:       new_schedule = (scheduled_at && scheduled_at.respond_to?(:utc)) ? scheduled_at.utc : Time.now.utc
20: 
21:       if worker_method =~ /^async_(\w+)/
22:         method_name = $1
23:         worker_options = compact(:worker => worker_name,:worker_key => worker_key,
24:                                  :worker_method => method_name,:job_key => job_key, :arg => arg)
25:         run_method(host_info,:ask_work,worker_options)
26:       elsif worker_method =~ /^enq_(\w+)/i
27:         raise NoJobKey.new("Must specify a job key with enqueued tasks") if job_key.blank?
28:         method_name = $1
29:         marshalled_args = Marshal.dump(arg)
30:         enqueue_task(compact(:worker_name => worker_name.to_s,:worker_key => worker_key.to_s,
31:                              :worker_method => method_name.to_s,:job_key => job_key.to_s,
32:                              :args => marshalled_args,:timeout => arguments ? arguments[:timeout] : nil,:scheduled_at => new_schedule))
33:        elsif worker_method =~ /^deq_(\w+)/i
34:         raise NoJobKey.new("Must specify a job key to dequeue tasks") if job_key.blank?
35:         method_name = $1
36:         dequeue_task(compact(:worker_name => worker_name.to_s,:worker_key => worker_key.to_s,
37:                              :worker_method => method_name.to_s,:job_key => job_key.to_s))
38:       else
39:         worker_options = compact(:worker => worker_name,:worker_key => worker_key,
40:                                  :worker_method => worker_method,:job_key => job_key,:arg => arg)
41:         run_method(host_info,:send_request,worker_options)
42:       end
43:     end
reset_memcache_result(job_key,value) click to toggle source

reset result within memcache for given key

     # File lib/backgroundrb/rails_worker_proxy.rb, line 120
120:     def reset_memcache_result(job_key,value)
121:       options = compact(:worker => worker_name,:worker_key => worker_key,\
122:                           :job_key => job_key)
123:       key = gen_key(options)
124:       middle_man.cache[key] = value
125:       value
126:     end
return_result(result) click to toggle source

(Not documented)

     # File lib/backgroundrb/rails_worker_proxy.rb, line 128
128:     def return_result result
129:       result = Array(result)
130:       result.size <= 1 ? result[0] : result
131:     end
return_result_from_memcache(options = {}) click to toggle source

return result from memcache

     # File lib/backgroundrb/rails_worker_proxy.rb, line 115
115:     def return_result_from_memcache options = {}
116:       middle_man.cache[gen_key(options)]
117:     end
run_method(host_info,method_name,worker_options = {}) click to toggle source

invoke method on worker

    # File lib/backgroundrb/rails_worker_proxy.rb, line 56
56:     def run_method host_info,method_name,worker_options = {}
57:       result = []
58:       connection = choose_connection(host_info)
59:       raise NoServerAvailable.new("No BackgrounDRb server is found running") if connection.blank?
60:       if host_info == :local or host_info.is_a?(String)
61:         result << invoke_on_connection(connection,method_name,worker_options)
62:       elsif host_info == :all
63:         succeeded = false
64:         begin
65:           connection.each { |conn| result << invoke_on_connection(conn,method_name,worker_options) }
66:           succeeded = true
67:         rescue BdrbConnError; end
68:         raise NoServerAvailable.new("No BackgrounDRb server is found running") unless succeeded
69:       else
70:         @tried_connections = [connection.server_info]
71:         begin
72:           result << invoke_on_connection(connection,method_name,worker_options)
73:         rescue BdrbConnError => e
74:           connection = middle_man.find_next_except_these(@tried_connections)
75:           @tried_connections << connection.server_info
76:           retry
77:         end
78:       end
79:       return nil if method_name == :ask_work
80:       return_result(result)
81:     end
worker_info() click to toggle source

return runtime information about worker

     # File lib/backgroundrb/rails_worker_proxy.rb, line 102
102:     def worker_info
103:       t_connections = middle_man.backend_connections
104:       result = t_connections.map { |conn| conn.worker_info(compact(:worker => worker_name,:worker_key => worker_key)) }
105:       return_result(result)
106:     end

secsequence

--- SEC00014

seccomment

--- ""

attributes

--- 
- name: data
  rw: RW
  a_desc: ""
- name: middle_man
  rw: RW
  a_desc: ""
- name: worker_key
  rw: RW
  a_desc: ""
- name: worker_method
  rw: RW
  a_desc: ""
- name: worker_name
  rw: RW
  a_desc: ""

method_list

--- 
- methods: 
  - visibility: public
    aref: M000100
    name: new
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 7</span>\n 7:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>(<span class=\"ruby-identifier\">p_worker_name</span>,<span class=\"ruby-identifier\">p_worker_key</span> = <span class=\"ruby-keyword kw\">nil</span>,<span class=\"ruby-identifier\">p_middle_man</span> = <span class=\"ruby-keyword kw\">nil</span>)\n 8:       <span class=\"ruby-ivar\">@worker_name</span> = <span class=\"ruby-identifier\">p_worker_name</span>\n 9:       <span class=\"ruby-ivar\">@middle_man</span> = <span class=\"ruby-identifier\">p_middle_man</span>\n\
      10:       <span class=\"ruby-ivar\">@worker_key</span> = <span class=\"ruby-identifier\">p_worker_key</span>\n\
      11:       <span class=\"ruby-ivar\">@tried_connections</span> = []\n\
      12:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      create new worker proxy
      </p>
    params: (p_worker_name,p_worker_key = nil,p_middle_man = nil)
  category: Class
  type: Public
- methods: 
  - visibility: public
    aref: M000106
    name: ask_result
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 91</span>\n\
      91:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">ask_result</span> <span class=\"ruby-identifier\">job_key</span>\n\
      92:       <span class=\"ruby-identifier\">options</span> = <span class=\"ruby-identifier\">compact</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\">:job_key</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">job_key</span>)\n\
      93:       <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-constant\">BDRB_CONFIG</span>[<span class=\"ruby-identifier\">:backgroundrb</span>][<span class=\"ruby-identifier\">:result_storage</span>] <span class=\"ruby-operator\">==</span> <span class=\"ruby-value str\">'memcache'</span>\n\
      94:         <span class=\"ruby-identifier\">return_result_from_memcache</span>(<span class=\"ruby-identifier\">options</span>)\n\
      95:       <span class=\"ruby-keyword kw\">else</span>\n\
      96:         <span class=\"ruby-identifier\">result</span> = <span class=\"ruby-identifier\">middle_man</span>.<span class=\"ruby-identifier\">backend_connections</span>.<span class=\"ruby-identifier\">map</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">conn</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">conn</span>.<span class=\"ruby-identifier\">ask_result</span>(<span class=\"ruby-identifier\">options</span>) }\n\
      97:         <span class=\"ruby-identifier\">return_result</span>(<span class=\"ruby-identifier\">result</span>)\n\
      98:       <span class=\"ruby-keyword kw\">end</span>\n\
      99:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      get results back from the cache. Cache can be in-memory worker cache or
      memcache based cache
      </p>
    params: (job_key)
  - visibility: public
    aref: M000113
    name: choose_connection
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 142</span>\n\
      142:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">choose_connection</span> <span class=\"ruby-identifier\">host_info</span>\n\
      143:       <span class=\"ruby-keyword kw\">case</span> <span class=\"ruby-identifier\">host_info</span>\n\
      144:       <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-identifier\">:all</span>; <span class=\"ruby-identifier\">middle_man</span>.<span class=\"ruby-identifier\">backend_connections</span>\n\
      145:       <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-identifier\">:local</span>; <span class=\"ruby-identifier\">middle_man</span>.<span class=\"ruby-identifier\">find_local</span>\n\
      146:       <span class=\"ruby-keyword kw\">when</span> <span class=\"ruby-constant\">String</span>; <span class=\"ruby-identifier\">middle_man</span>.<span class=\"ruby-identifier\">find_connection</span>(<span class=\"ruby-identifier\">host_info</span>)\n\
      147:       <span class=\"ruby-keyword kw\">else</span>; <span class=\"ruby-identifier\">middle_man</span>.<span class=\"ruby-identifier\">choose_server</span>\n\
      148:       <span class=\"ruby-keyword kw\">end</span>\n\
      149:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      choose a worker
      </p>
    params: (host_info)
  - visibility: public
    aref: M000114
    name: compact
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 152</span>\n\
      152:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">compact</span>(<span class=\"ruby-identifier\">options</span> = { })\n\
      153:       <span class=\"ruby-identifier\">options</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\">nil?</span> }\n\
      154:       <span class=\"ruby-identifier\">options</span>\n\
      155:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      helper method to compact a hash and for getting rid of nil parameters
      </p>
    params: (options = { })
  - visibility: public
    aref: M000112
    name: delete
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 134</span>\n\
      134:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">delete</span>\n\
      135:       <span class=\"ruby-identifier\">middle_man</span>.<span class=\"ruby-identifier\">backend_connections</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">connection</span><span class=\"ruby-operator\">|</span>\n\
      136:         <span class=\"ruby-identifier\">connection</span>.<span class=\"ruby-identifier\">delete_worker</span>(<span class=\"ruby-identifier\">compact</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>))\n\
      137:       <span class=\"ruby-keyword kw\">end</span>\n\
      138:       <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">worker_key</span>\n\
      139:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      delete a worker
      </p>
    params: ()
  - visibility: public
    aref: M000103
    name: dequeue_task
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 51</span>\n\
      51:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">dequeue_task</span> <span class=\"ruby-identifier\">options</span> = {}\n\
      52:       <span class=\"ruby-constant\">BdrbJobQueue</span>.<span class=\"ruby-identifier\">remove_job</span>(<span class=\"ruby-identifier\">options</span>)\n\
      53:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      remove tasks from the worker pool
      </p>
    params: (options = {})
  - visibility: public
    aref: M000102
    name: enqueue_task
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 46</span>\n\
      46:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">enqueue_task</span> <span class=\"ruby-identifier\">options</span> = {}\n\
      47:       <span class=\"ruby-constant\">BdrbJobQueue</span>.<span class=\"ruby-identifier\">insert_job</span>(<span class=\"ruby-identifier\">options</span>)\n\
      48:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      enqueue tasks to the worker pool
      </p>
    params: (options = {})
  - visibility: public
    aref: M000108
    name: gen_key
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 109</span>\n\
      109:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">gen_key</span> <span class=\"ruby-identifier\">options</span>\n\
      110:       <span class=\"ruby-identifier\">key</span> = [<span class=\"ruby-identifier\">options</span>[<span class=\"ruby-identifier\">:worker</span>],<span class=\"ruby-identifier\">options</span>[<span class=\"ruby-identifier\">:worker_key</span>],<span class=\"ruby-identifier\">options</span>[<span class=\"ruby-identifier\">:job_key</span>]].<span class=\"ruby-identifier\">compact</span>.<span class=\"ruby-identifier\">join</span>(<span class=\"ruby-value str\">'_'</span>)\n\
      111:       <span class=\"ruby-identifier\">key</span>\n\
      112:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      generate worker key
      </p>
    params: (options)
  - visibility: public
    aref: M000105
    name: invoke_on_connection
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 84</span>\n\
      84:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">invoke_on_connection</span> <span class=\"ruby-identifier\">connection</span>,<span class=\"ruby-identifier\">method_name</span>,<span class=\"ruby-identifier\">options</span> = {}\n\
      85:       <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">NoServerAvailable</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-value str\">&quot;No BackgrounDRb is found running&quot;</span>) <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">connection</span>\n\
      86:       <span class=\"ruby-identifier\">connection</span>.<span class=\"ruby-identifier\">send</span>(<span class=\"ruby-identifier\">method_name</span>,<span class=\"ruby-identifier\">options</span>)\n\
      87:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      choose a backgroundrb server connection and invoke worker method on it.
      </p>
    params: (connection,method_name,options = {})
  - visibility: public
    aref: M000101
    name: method_missing
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 14</span>\n\
      14:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">method_missing</span>(<span class=\"ruby-identifier\">method_id</span>,<span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">args</span>)\n\
      15:       <span class=\"ruby-identifier\">worker_method</span> = <span class=\"ruby-identifier\">method_id</span>.<span class=\"ruby-identifier\">to_s</span>\n\
      16:       <span class=\"ruby-identifier\">arguments</span> = <span class=\"ruby-identifier\">args</span>.<span class=\"ruby-identifier\">first</span>\n\
      17: \n\
      18:       <span class=\"ruby-identifier\">arg</span>,<span class=\"ruby-identifier\">job_key</span>,<span class=\"ruby-identifier\">host_info</span>,<span class=\"ruby-identifier\">scheduled_at</span> = <span class=\"ruby-identifier\">arguments</span> <span class=\"ruby-operator\">&amp;&amp;</span> <span class=\"ruby-identifier\">arguments</span>.<span class=\"ruby-identifier\">values_at</span>(<span class=\"ruby-identifier\">:arg</span>,<span class=\"ruby-identifier\">:job_key</span>,<span class=\"ruby-identifier\">:host</span>,<span class=\"ruby-identifier\">:scheduled_at</span>)\n\
      19:       <span class=\"ruby-identifier\">new_schedule</span> = (<span class=\"ruby-identifier\">scheduled_at</span> <span class=\"ruby-operator\">&amp;&amp;</span> <span class=\"ruby-identifier\">scheduled_at</span>.<span class=\"ruby-identifier\">respond_to?</span>(<span class=\"ruby-identifier\">:utc</span>)) <span class=\"ruby-operator\">?</span> <span class=\"ruby-identifier\">scheduled_at</span>.<span class=\"ruby-identifier\">utc</span> <span class=\"ruby-operator\">:</span> <span class=\"ruby-constant\">Time</span>.<span class=\"ruby-identifier\">now</span>.<span class=\"ruby-identifier\">utc</span>\n\
      20: \n\
      21:       <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">worker_method</span> <span class=\"ruby-operator\">=~</span> <span class=\"ruby-regexp re\">/^async_(\\w+)/</span>\n\
      22:         <span class=\"ruby-identifier\">method_name</span> = <span class=\"ruby-identifier\">$1</span>\n\
      23:         <span class=\"ruby-identifier\">worker_options</span> = <span class=\"ruby-identifier\">compact</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>,\n\
      24:                                  <span class=\"ruby-identifier\">:worker_method</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">method_name</span>,<span class=\"ruby-identifier\">:job_key</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">job_key</span>, <span class=\"ruby-identifier\">:arg</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">arg</span>)\n\
      25:         <span class=\"ruby-identifier\">run_method</span>(<span class=\"ruby-identifier\">host_info</span>,<span class=\"ruby-identifier\">:ask_work</span>,<span class=\"ruby-identifier\">worker_options</span>)\n\
      26:       <span class=\"ruby-keyword kw\">elsif</span> <span class=\"ruby-identifier\">worker_method</span> <span class=\"ruby-operator\">=~</span> <span class=\"ruby-regexp re\">/^enq_(\\w+)/i</span>\n\
      27:         <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">NoJobKey</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-value str\">&quot;Must specify a job key with enqueued tasks&quot;</span>) <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">job_key</span>.<span class=\"ruby-identifier\">blank?</span>\n\
      28:         <span class=\"ruby-identifier\">method_name</span> = <span class=\"ruby-identifier\">$1</span>\n\
      29:         <span class=\"ruby-identifier\">marshalled_args</span> = <span class=\"ruby-constant\">Marshal</span>.<span class=\"ruby-identifier\">dump</span>(<span class=\"ruby-identifier\">arg</span>)\n\
      30:         <span class=\"ruby-identifier\">enqueue_task</span>(<span class=\"ruby-identifier\">compact</span>(<span class=\"ruby-identifier\">:worker_name</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">worker_name</span>.<span class=\"ruby-identifier\">to_s</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\">to_s</span>,\n\
      31:                              <span class=\"ruby-identifier\">:worker_method</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">method_name</span>.<span class=\"ruby-identifier\">to_s</span>,<span class=\"ruby-identifier\">:job_key</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">job_key</span>.<span class=\"ruby-identifier\">to_s</span>,\n\
      32:                              <span class=\"ruby-identifier\">:args</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">marshalled_args</span>,<span class=\"ruby-identifier\">:timeout</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">arguments</span> <span class=\"ruby-value\">? </span><span class=\"ruby-identifier\">arguments</span>[<span class=\"ruby-identifier\">:timeout</span>] <span class=\"ruby-operator\">:</span> <span class=\"ruby-keyword kw\">nil</span>,<span class=\"ruby-identifier\">:scheduled_at</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">new_schedule</span>))\n\
      33:        <span class=\"ruby-keyword kw\">elsif</span> <span class=\"ruby-identifier\">worker_method</span> <span class=\"ruby-operator\">=~</span> <span class=\"ruby-regexp re\">/^deq_(\\w+)/i</span>\n\
      34:         <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">NoJobKey</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-value str\">&quot;Must specify a job key to dequeue tasks&quot;</span>) <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">job_key</span>.<span class=\"ruby-identifier\">blank?</span>\n\
      35:         <span class=\"ruby-identifier\">method_name</span> = <span class=\"ruby-identifier\">$1</span>\n\
      36:         <span class=\"ruby-identifier\">dequeue_task</span>(<span class=\"ruby-identifier\">compact</span>(<span class=\"ruby-identifier\">:worker_name</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">worker_name</span>.<span class=\"ruby-identifier\">to_s</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\">to_s</span>,\n\
      37:                              <span class=\"ruby-identifier\">:worker_method</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">method_name</span>.<span class=\"ruby-identifier\">to_s</span>,<span class=\"ruby-identifier\">:job_key</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">job_key</span>.<span class=\"ruby-identifier\">to_s</span>))\n\
      38:       <span class=\"ruby-keyword kw\">else</span>\n\
      39:         <span class=\"ruby-identifier\">worker_options</span> = <span class=\"ruby-identifier\">compact</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>,\n\
      40:                                  <span class=\"ruby-identifier\">:worker_method</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">worker_method</span>,<span class=\"ruby-identifier\">:job_key</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">job_key</span>,<span class=\"ruby-identifier\">:arg</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">arg</span>)\n\
      41:         <span class=\"ruby-identifier\">run_method</span>(<span class=\"ruby-identifier\">host_info</span>,<span class=\"ruby-identifier\">:send_request</span>,<span class=\"ruby-identifier\">worker_options</span>)\n\
      42:       <span class=\"ruby-keyword kw\">end</span>\n\
      43:     <span class=\"ruby-keyword kw\">end</span>"
    params: (method_id,*args)
  - visibility: public
    aref: M000110
    name: reset_memcache_result
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 120</span>\n\
      120:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">reset_memcache_result</span>(<span class=\"ruby-identifier\">job_key</span>,<span class=\"ruby-identifier\">value</span>)\n\
      121:       <span class=\"ruby-identifier\">options</span> = <span class=\"ruby-identifier\">compact</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>,\\\n\
      122:                           <span class=\"ruby-identifier\">:job_key</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">job_key</span>)\n\
      123:       <span class=\"ruby-identifier\">key</span> = <span class=\"ruby-identifier\">gen_key</span>(<span class=\"ruby-identifier\">options</span>)\n\
      124:       <span class=\"ruby-identifier\">middle_man</span>.<span class=\"ruby-identifier\">cache</span>[<span class=\"ruby-identifier\">key</span>] = <span class=\"ruby-identifier\">value</span>\n\
      125:       <span class=\"ruby-identifier\">value</span>\n\
      126:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      reset result within memcache for given key
      </p>
    params: (job_key,value)
  - visibility: public
    aref: M000111
    name: return_result
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 128</span>\n\
      128:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">return_result</span> <span class=\"ruby-identifier\">result</span>\n\
      129:       <span class=\"ruby-identifier\">result</span> = <span class=\"ruby-constant\">Array</span>(<span class=\"ruby-identifier\">result</span>)\n\
      130:       <span class=\"ruby-identifier\">result</span>.<span class=\"ruby-identifier\">size</span> <span class=\"ruby-operator\">&lt;=</span> <span class=\"ruby-value\">1</span> <span class=\"ruby-operator\">?</span> <span class=\"ruby-identifier\">result</span>[<span class=\"ruby-value\">0</span>] <span class=\"ruby-operator\">:</span> <span class=\"ruby-identifier\">result</span>\n\
      131:     <span class=\"ruby-keyword kw\">end</span>"
    params: (result)
  - visibility: public
    aref: M000109
    name: return_result_from_memcache
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 115</span>\n\
      115:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">return_result_from_memcache</span> <span class=\"ruby-identifier\">options</span> = {}\n\
      116:       <span class=\"ruby-identifier\">middle_man</span>.<span class=\"ruby-identifier\">cache</span>[<span class=\"ruby-identifier\">gen_key</span>(<span class=\"ruby-identifier\">options</span>)]\n\
      117:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      return result from memcache
      </p>
    params: (options = {})
  - visibility: public
    aref: M000104
    name: run_method
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 56</span>\n\
      56:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">run_method</span> <span class=\"ruby-identifier\">host_info</span>,<span class=\"ruby-identifier\">method_name</span>,<span class=\"ruby-identifier\">worker_options</span> = {}\n\
      57:       <span class=\"ruby-identifier\">result</span> = []\n\
      58:       <span class=\"ruby-identifier\">connection</span> = <span class=\"ruby-identifier\">choose_connection</span>(<span class=\"ruby-identifier\">host_info</span>)\n\
      59:       <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">NoServerAvailable</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-value str\">&quot;No BackgrounDRb server is found running&quot;</span>) <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">connection</span>.<span class=\"ruby-identifier\">blank?</span>\n\
      60:       <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">host_info</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-identifier\">:local</span> <span class=\"ruby-keyword kw\">or</span> <span class=\"ruby-identifier\">host_info</span>.<span class=\"ruby-identifier\">is_a?</span>(<span class=\"ruby-constant\">String</span>)\n\
      61:         <span class=\"ruby-identifier\">result</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">invoke_on_connection</span>(<span class=\"ruby-identifier\">connection</span>,<span class=\"ruby-identifier\">method_name</span>,<span class=\"ruby-identifier\">worker_options</span>)\n\
      62:       <span class=\"ruby-keyword kw\">elsif</span> <span class=\"ruby-identifier\">host_info</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-identifier\">:all</span>\n\
      63:         <span class=\"ruby-identifier\">succeeded</span> = <span class=\"ruby-keyword kw\">false</span>\n\
      64:         <span class=\"ruby-keyword kw\">begin</span>\n\
      65:           <span class=\"ruby-identifier\">connection</span>.<span class=\"ruby-identifier\">each</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">conn</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">result</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">invoke_on_connection</span>(<span class=\"ruby-identifier\">conn</span>,<span class=\"ruby-identifier\">method_name</span>,<span class=\"ruby-identifier\">worker_options</span>) }\n\
      66:           <span class=\"ruby-identifier\">succeeded</span> = <span class=\"ruby-keyword kw\">true</span>\n\
      67:         <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">BdrbConnError</span>; <span class=\"ruby-keyword kw\">end</span>\n\
      68:         <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">NoServerAvailable</span>.<span class=\"ruby-identifier\">new</span>(<span class=\"ruby-value str\">&quot;No BackgrounDRb server is found running&quot;</span>) <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">succeeded</span>\n\
      69:       <span class=\"ruby-keyword kw\">else</span>\n\
      70:         <span class=\"ruby-ivar\">@tried_connections</span> = [<span class=\"ruby-identifier\">connection</span>.<span class=\"ruby-identifier\">server_info</span>]\n\
      71:         <span class=\"ruby-keyword kw\">begin</span>\n\
      72:           <span class=\"ruby-identifier\">result</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">invoke_on_connection</span>(<span class=\"ruby-identifier\">connection</span>,<span class=\"ruby-identifier\">method_name</span>,<span class=\"ruby-identifier\">worker_options</span>)\n\
      73:         <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">BdrbConnError</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">e</span>\n\
      74:           <span class=\"ruby-identifier\">connection</span> = <span class=\"ruby-identifier\">middle_man</span>.<span class=\"ruby-identifier\">find_next_except_these</span>(<span class=\"ruby-ivar\">@tried_connections</span>)\n\
      75:           <span class=\"ruby-ivar\">@tried_connections</span> <span class=\"ruby-operator\">&lt;&lt;</span> <span class=\"ruby-identifier\">connection</span>.<span class=\"ruby-identifier\">server_info</span>\n\
      76:           <span class=\"ruby-keyword kw\">retry</span>\n\
      77:         <span class=\"ruby-keyword kw\">end</span>\n\
      78:       <span class=\"ruby-keyword kw\">end</span>\n\
      79:       <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">nil</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">method_name</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-identifier\">:ask_work</span>\n\
      80:       <span class=\"ruby-identifier\">return_result</span>(<span class=\"ruby-identifier\">result</span>)\n\
      81:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      invoke method on worker
      </p>
    params: (host_info,method_name,worker_options = {})
  - visibility: public
    aref: M000107
    name: worker_info
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/backgroundrb/rails_worker_proxy.rb, line 102</span>\n\
      102:     <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">worker_info</span>\n\
      103:       <span class=\"ruby-identifier\">t_connections</span> = <span class=\"ruby-identifier\">middle_man</span>.<span class=\"ruby-identifier\">backend_connections</span>\n\
      104:       <span class=\"ruby-identifier\">result</span> = <span class=\"ruby-identifier\">t_connections</span>.<span class=\"ruby-identifier\">map</span> { <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">conn</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">conn</span>.<span class=\"ruby-identifier\">worker_info</span>(<span class=\"ruby-identifier\">compact</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>)) }\n\
      105:       <span class=\"ruby-identifier\">return_result</span>(<span class=\"ruby-identifier\">result</span>)\n\
      106:     <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      return runtime information about worker
      </p>
    params: ()
  category: Instance
  type: Public

sectitle

--- 

[Validate]

Generated with the Darkfish Rdoc Generator.