Class: Workerholic::Manager
- Inherits:
-
Object
- Object
- Workerholic::Manager
- Defined in:
- lib/workerholic/manager.rb
Overview
Handles polling from Redis and hands job to worker
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#scheduler ⇒ Object
readonly
Returns the value of attribute scheduler.
-
#worker_balancer ⇒ Object
readonly
Returns the value of attribute worker_balancer.
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Manager
constructor
A new instance of Manager.
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Manager
Returns a new instance of Manager.
6 7 8 9 10 11 12 13 14 |
# File 'lib/workerholic/manager.rb', line 6 def initialize(opts = {}) @workers = [] Workerholic.workers_count.times { @workers << Worker.new } @scheduler = JobScheduler.new(sorted_set: opts[:sorted_set]) @worker_balancer = WorkerBalancer.new(workers: workers, auto_balance: opts[:auto_balance]) @logger = LogManager.new end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
4 5 6 |
# File 'lib/workerholic/manager.rb', line 4 def logger @logger end |
#scheduler ⇒ Object (readonly)
Returns the value of attribute scheduler.
4 5 6 |
# File 'lib/workerholic/manager.rb', line 4 def scheduler @scheduler end |
#worker_balancer ⇒ Object (readonly)
Returns the value of attribute worker_balancer.
4 5 6 |
# File 'lib/workerholic/manager.rb', line 4 def worker_balancer @worker_balancer end |
#workers ⇒ Object (readonly)
Returns the value of attribute workers.
4 5 6 |
# File 'lib/workerholic/manager.rb', line 4 def workers @workers end |
Instance Method Details
#shutdown ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/workerholic/manager.rb', line 29 def shutdown workers.each(&:kill) worker_balancer.kill scheduler.kill Starter.kill_memory_tracker_thread workers.each(&:join) scheduler.join end |
#start ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/workerholic/manager.rb', line 16 def start worker_balancer.start workers.each(&:work) scheduler.start sleep rescue SystemExit, Interrupt logger.info("Workerholic's process #{Process.pid} is gracefully shutting down, letting workers finish their current jobs...") shutdown exit end |