Class: Workerholic::WorkerBalancer

Inherits:
Object
  • Object
show all
Defined in:
lib/workerholic/worker_balancer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ WorkerBalancer

Returns a new instance of WorkerBalancer.



6
7
8
9
10
11
12
13
# File 'lib/workerholic/worker_balancer.rb', line 6

def initialize(opts = {})
  @storage = Storage::RedisWrapper.new
  @queues = fetch_queues
  @workers = opts[:workers] || []
  @alive = true
  @logger = LogManager.new
  @auto = opts[:auto_balance]
end

Instance Attribute Details

#aliveObject (readonly)

Returns the value of attribute alive.



3
4
5
# File 'lib/workerholic/worker_balancer.rb', line 3

def alive
  @alive
end

#autoObject (readonly)

Returns the value of attribute auto.



3
4
5
# File 'lib/workerholic/worker_balancer.rb', line 3

def auto
  @auto
end

#queuesObject

Returns the value of attribute queues.



4
5
6
# File 'lib/workerholic/worker_balancer.rb', line 4

def queues
  @queues
end

#storageObject (readonly)

Returns the value of attribute storage.



3
4
5
# File 'lib/workerholic/worker_balancer.rb', line 3

def storage
  @storage
end

#threadObject (readonly)

Returns the value of attribute thread.



3
4
5
# File 'lib/workerholic/worker_balancer.rb', line 3

def thread
  @thread
end

#workersObject (readonly)

Returns the value of attribute workers.



3
4
5
# File 'lib/workerholic/worker_balancer.rb', line 3

def workers
  @workers
end

Instance Method Details

#killObject



23
24
25
# File 'lib/workerholic/worker_balancer.rb', line 23

def kill
  thread.kill
end

#startObject



15
16
17
18
19
20
21
# File 'lib/workerholic/worker_balancer.rb', line 15

def start
  if auto
    auto_balance_workers
  else
    evenly_balance_workers
  end
end