Class: WorkerArmy::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/worker_army/base.rb

Direct Known Subclasses

Client, Queue, Worker

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/worker_army/base.rb', line 3

def config
  @config
end

Class Method Details

.client_retry_count(conf = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/worker_army/base.rb', line 35

def client_retry_count(conf = nil)
  if ENV['worker_army_client_retry_count']
    return ENV['worker_army_client_retry_count'].to_i
  elsif conf and conf['client_retry_count']
    return conf['client_retry_count'].to_i
  else
    return 10
  end
end

.configObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/worker_army/base.rb', line 6

def config
  if ENV['worker_army_redis_host'] and ENV['worker_army_redis_port']
    config = { 'redis_host' => ENV['worker_army_redis_host'], 'redis_port' => ENV['worker_army_redis_port'] }
    if ENV['worker_army_redis_auth']
      config['redis_auth'] = ENV['worker_army_redis_auth']
    end
    if ENV['worker_army_worker_retry_count']
      config['worker_retry_count'] = ENV['worker_army_worker_retry_count'].to_i
    end
    if ENV['worker_army_client_retry_count']
      config['client_retry_count'] = ENV['worker_army_client_retry_count'].to_i
    end
    if ENV['worker_army_callback_retry_count']
      config['callback_retry_count'] = ENV['worker_army_callback_retry_count'].to_i
    end
    if ENV['worker_army_endpoint']
      config['endpoint'] = ENV['worker_army_endpoint']
    end
  else
    begin
      # puts "Using config in your home directory"
      config = YAML.load(File.read("#{ENV['HOME']}/.worker_army.yml"))
    rescue Errno::ENOENT
      raise "worker-army configuration expected in ~/.worker_army.yml or provide env vars..."
    end
  end
  config
end

Instance Method Details

#callback_retry_count(conf = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/worker_army/base.rb', line 56

def callback_retry_count(conf = nil)
  if ENV['worker_army_callback_retry_count']
    return ENV['worker_army_callback_retry_count'].to_i
  elsif conf and conf['callback_retry_count']
    return conf['callback_retry_count'].to_i
  else
    return 3
  end
end

#worker_retry_count(conf = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/worker_army/base.rb', line 46

def worker_retry_count(conf = nil)
  if ENV['worker_army_worker_retry_count']
    return ENV['worker_army_worker_retry_count'].to_i
  elsif conf and conf['worker_retry_count']
    return conf['worker_retry_count'].to_i
  else
    return 10
  end
end