Class: Fleiss::Worker
- Inherits:
-
Object
- Object
- Fleiss::Worker
- Defined in:
- lib/fleiss/worker.rb
Instance Attribute Summary collapse
-
#queues ⇒ Object
readonly
Returns the value of attribute queues.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
-
#wait_time ⇒ Object
readonly
Returns the value of attribute wait_time.
Class Method Summary collapse
-
.run(**opts) ⇒ Object
Shortcut for new(**opts).run.
Instance Method Summary collapse
-
#initialize(queues: [Fleiss::DEFAULT_QUEUE], concurrency: 10, wait_time: 1) ⇒ Worker
constructor
Init a new worker instance.
-
#run ⇒ Object
Run starts the worker.
Constructor Details
#initialize(queues: [Fleiss::DEFAULT_QUEUE], concurrency: 10, wait_time: 1) ⇒ Worker
Init a new worker instance
17 18 19 20 21 22 |
# File 'lib/fleiss/worker.rb', line 17 def initialize(queues: [Fleiss::DEFAULT_QUEUE], concurrency: 10, wait_time: 1) @uuid = SecureRandom.uuid @queues = Array(queues) @pool = Fleiss::Executor.new(max_size: concurrency) @wait_time = wait_time end |
Instance Attribute Details
#queues ⇒ Object (readonly)
Returns the value of attribute queues.
6 7 8 |
# File 'lib/fleiss/worker.rb', line 6 def queues @queues end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
6 7 8 |
# File 'lib/fleiss/worker.rb', line 6 def uuid @uuid end |
#wait_time ⇒ Object (readonly)
Returns the value of attribute wait_time.
6 7 8 |
# File 'lib/fleiss/worker.rb', line 6 def wait_time @wait_time end |
Class Method Details
.run(**opts) ⇒ Object
Shortcut for new(**opts).run
9 10 11 |
# File 'lib/fleiss/worker.rb', line 9 def self.run(**opts) new(**opts).run end |
Instance Method Details
#run ⇒ Object
Run starts the worker
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fleiss/worker.rb', line 25 def run log(:info) { "Worker #{uuid} starting - queues: #{queues.inspect}, concurrency: #{@pool.max_size}" } loop do run_cycle sleep @wait_time end rescue SignalException => e log(:info) { "Worker #{uuid} received #{e.message}. Shutting down..." } ensure @pool.shutdown @pool.wait_for_termination end |