Class: Woodhouse::Layout::Worker
- Inherits:
-
Object
- Object
- Woodhouse::Layout::Worker
- Defined in:
- lib/woodhouse/layout.rb
Overview
A Worker describes a single job that is performed on a Server. One or more Runner actors are created for every Worker in a Node.
Any Worker has three parameters used to route jobs to it:
worker_class_name
-
This is generally a class name. It’s looked up in a Registry and used to instantiate a job object.
job_method
-
This is a method on the object called up with
worker_class_name
. criteria
-
A hash of values (actually, a QueueCriteria object) used to filter only specific jobs to this worker. When a job is dispatched, its
arguments
are compared with a worker’scriteria
. This is done via an AMQP headers exchange (TODO: need to have a central document to reference on how Woodhouse uses AMQP and jobs are dispatched)
Instance Attribute Summary collapse
-
#criteria ⇒ Object
Returns the value of attribute criteria.
-
#job_method ⇒ Object
Returns the value of attribute job_method.
-
#threads ⇒ Object
Returns the value of attribute threads.
-
#worker_class_name ⇒ Object
Returns the value of attribute worker_class_name.
Instance Method Summary collapse
-
#==(other) ⇒ Object
TODO: want to recognize increases and decreases in numbers of threads and make minimal changes.
- #accepts_job?(job) ⇒ Boolean
- #describe ⇒ Object
- #exchange_name ⇒ Object
- #frozen_clone ⇒ Object
-
#initialize(worker_class_name, job_method, opts = {}) ⇒ Worker
constructor
A new instance of Worker.
- #queue_name ⇒ Object
Constructor Details
#initialize(worker_class_name, job_method, opts = {}) ⇒ Worker
Returns a new instance of Worker.
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/woodhouse/layout.rb', line 192 def initialize(worker_class_name, job_method, opts = {}) opts = opts.clone self.worker_class_name = worker_class_name self.job_method = job_method self.threads = opts.delete(:threads) || 1 self.criteria = opts.delete(:only) unless opts.keys.empty? raise ArgumentError, "unknown option keys: #{opts.keys.inspect}" end end |
Instance Attribute Details
#criteria ⇒ Object
Returns the value of attribute criteria.
190 191 192 |
# File 'lib/woodhouse/layout.rb', line 190 def criteria @criteria end |
#job_method ⇒ Object
Returns the value of attribute job_method.
190 191 192 |
# File 'lib/woodhouse/layout.rb', line 190 def job_method @job_method end |
#threads ⇒ Object
Returns the value of attribute threads.
190 191 192 |
# File 'lib/woodhouse/layout.rb', line 190 def threads @threads end |
#worker_class_name ⇒ Object
Returns the value of attribute worker_class_name.
190 191 192 |
# File 'lib/woodhouse/layout.rb', line 190 def worker_class_name @worker_class_name end |
Instance Method Details
#==(other) ⇒ Object
TODO: want to recognize increases and decreases in numbers of threads and make minimal changes
241 242 243 244 245 246 |
# File 'lib/woodhouse/layout.rb', line 241 def ==(other) [worker_class_name, job_method, threads, criteria] == [other.worker_class_name, other.job_method, other.threads, other.criteria] end |
#accepts_job?(job) ⇒ Boolean
235 236 237 |
# File 'lib/woodhouse/layout.rb', line 235 def accepts_job?(job) criteria.matches?(job.arguments) end |
#describe ⇒ Object
231 232 233 |
# File 'lib/woodhouse/layout.rb', line 231 def describe "#@worker_class_name##@job_method(#{@criteria.describe})" end |
#exchange_name ⇒ Object
203 204 205 |
# File 'lib/woodhouse/layout.rb', line 203 def exchange_name "#{worker_class_name}_#{job_method}".downcase end |
#frozen_clone ⇒ Object
227 228 229 |
# File 'lib/woodhouse/layout.rb', line 227 def frozen_clone clone.freeze end |
#queue_name ⇒ Object
207 208 209 |
# File 'lib/woodhouse/layout.rb', line 207 def queue_name exchange_name + criteria.queue_key end |