Class: Resque::Integration::Configuration::Worker

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/resque/integration/configuration.rb

Overview

Worker entity

Instance Method Summary collapse

Constructor Details

#initialize(queue, config) ⇒ Worker

Returns a new instance of Worker.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/resque/integration/configuration.rb', line 15

def initialize(queue, config)
  data = {:queue => queue}

  if config.is_a?(Hash)
    data.merge!(config.symbolize_keys)
  else
    data[:count] = config
  end

  super(data)
end

Instance Method Details

#countObject

Returns workers count for given queue



28
29
30
# File 'lib/resque/integration/configuration.rb', line 28

def count
  [super || 1, 1].max
end

#envObject

Returns hash of ENV variables that should be associated with this worker



33
34
35
36
37
38
39
40
41
42
# File 'lib/resque/integration/configuration.rb', line 33

def env
  env = super || {}

  env[:QUEUE] ||= queue
  env[:JOBS_PER_FORK] ||= jobs_per_fork if jobs_per_fork
  env[:MINUTES_PER_FORK] ||= minutes_per_fork if minutes_per_fork
  env[:SHUFFLE] ||= 1 if shuffle

  Hash[env.map { |k, v| [k, v.to_s] }]
end