Skip to content

Commit

Permalink
Конфигурирование переменных окружения
Browse files Browse the repository at this point in the history
  • Loading branch information
take-five committed Apr 2, 2013
1 parent 5a7c801 commit ec7b4e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,22 @@ resque:
verbosity: 1 # "шумность" логера (0 - ничего не пишет, 1 - пишет о начале/конце задачи, 2 - пишет все)
log_file: "log/resque.log" # путь до log-файла от корня проекта

# переменные окружения, которые надобно передавать в resque
env:
RUBY_HEAP_MIN_SLOTS: 2500000
RUBY_HEAP_SLOTS_INCREMENT: 1000000
RUBY_HEAP_SLOTS_GROWTH_FACTOR: 1
RUBY_GC_MALLOC_LIMIT: 50000000

# конфигурация воркеров (названия воркеров являются названиями очередей)
workers:
kirby: 2 # 2 воркера в очереди kirby
images:
count: 8 # 8 воркеров в очереди images
jobs_per_fork: 250 # каждый воркер обрабатывает 250 задач прежде, чем форкается заново
minutes_per_fork: 30 # альтернатива предыдущей настройке - сколько минут должен работать воркер, прежде чем форкнуться заново
env: # переменные окружение, специфичные для данного воркера
RUBY_HEAP_SLOTS_GROWTH_FACTOR: 0.5
```
Для разработки можно (и нужно) создать файл `config/resque.local.yml`, в котором можно переопределить любые параметры:
Expand Down
15 changes: 9 additions & 6 deletions lib/resque/integration/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ def initialize(queue, config)

# Returns hash of ENV variables that should be associated with this worker
def env
env = {:QUEUE => queue}
env[:JOBS_PER_FORK] = jobs_per_fork.to_s if jobs_per_fork
env[:MINUTES_PER_FORK] = minutes_per_fork.to_s if minutes_per_fork
env = super || {}

env
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

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

Expand Down Expand Up @@ -65,12 +67,13 @@ def log_file

# Returns environment variables that should be associated with this configuration
def env
env = {:INTERVAL => interval.to_s}
env = self['env'] || {}

env[:INTERVAL] ||= interval
env[:VERBOSE] = '1' if verbosity == 1
env[:VVERBOSE] = '1' if verbosity == 2

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

private
Expand Down

0 comments on commit ec7b4e5

Please sign in to comment.