本文介绍了Rails 自定义环境 Resque.enqueue 不创建作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Resque 用于几个异步作业.我已经设置了一个自定义环境 integration,它是我的 production 环境的克隆.但是,在我的 integration 环境中,我的 Resque 作业不会添加到 Redis.

I'm using Resque for a couple of asynchronous jobs. I've set up a custom environment integration which is a clone of my production environment. However, my Resque jobs do not get added to Redis in my integration environment.

例如,如果我运行以下命令:

For example, if I run the following:

$ RAILS_ENV=production rails console
> Resque.enqueue(MyLovelyJob, 1)

我会在 resque-web 中看到作业.

I will see the job appear in resque-web.

但是,如果我运行以下命令:

But, if I run the following:

$ RAILS_ENV=integration rails console
> Resque.enqueue(MyLovelyJob, 1)

该作业未出现在 resque-web 中.

The job does not appear in resque-web.

显然我缺少某种配置,我正在努力弄清楚它是什么.

Clearly I'm missing some kind of configuration, I'm pulling my hair out trying to work out what it is.

推荐答案

这是我为解决问题所做的:

This is what I did to fix the problem:

我使用以下内容创建了 config/initializers/resque.rb:

I created config/initializers/resque.rb with the following content:

rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
rails_env = ENV['RAILS_ENV'] || 'development'

resque_config = YAML.load_file(rails_root + '/config/resque.yml')
Resque.redis = resque_config[rails_env]

我还创建了具有以下内容的 config/resque.yml(显然这些应该设置为适当的):

I also created config/resque.yml with the following content (obviously these should be set to whatever is appropriate):

development: localhost:6379
test: localhost:6379
integration: localhost:6379
staging: localhost:6379
production: localhost:6379

这篇关于Rails 自定义环境 Resque.enqueue 不创建作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 15:12