开发者

how to get access ENV variables from within resque jobs

开发者 https://www.devze.com 2023-04-11 21:15 出处:网络
How do I make sure resque has access to all my ENV variables? I\'m trying to send an email from within a resque job and it cannot send because the actionmailer smtp username/pass are set via ENV varia

How do I make sure resque has access to all my ENV variables? I'm trying to send an email from within a resque job and it cannot send because the actionmailer smtp username/pass are set via ENV variables. It looks like even ENV['RAILS_ENV'] is not available from within the resque job.

Here's my resque.rake file:

# Run to start:
# rake resque:work QUEUE='*'
require 'resque/tasks'
require 'resque_scheduler/tasks'

task "resque:setup" => :environment do
  require 'resque'
  require 'resque_scheduler'
  require 'resque/scheduler'

  Resque.schedule = YAML.load_file("#{Rails.root}/config/resque_schedule.yml")
end

Here's my resque.rb initializer:

require 'resque_scheduler'
Resque.redis = 'localhost:6379'
Dir["#{Rails.root}/app/jobs/*.rb"].each { |file| require file }

Here's my procfile that starts redis/resque/resque worker

mongo:            mongod
redis-server:     redis-server /usr/local/etc/redis.con开发者_如何学Cf
scheduler:        bundle exec rake resque:scheduler
worker:           bundle exec rake resque:work QUEUE=images, notifications


Add them to resque.rake

task "resque:setup" => :environment do
  # ... other stuff
  ENV['RAILS_ENV'] = Rails.env
end


Well I can't tell for sure but if this is UNIX, open /proc/self/environ will work even if there's no language facility to read ENV.

This is, of course, last resort.

0

精彩评论

暂无评论...
验证码 换一张
取 消