Rails Daemon 保持开发模式
我有一个带有守护进程的 Rails 应用程序,用于检查邮箱中是否有新电子邮件。 我正在使用 Fetcher 插件来完成此任务。 守护程序文件如下所示:
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment.rb'
class MailFetcherDaemon < Daemon::Base
@config = YAML.load_file("#{RAILS_ROOT}/config/mail.yml")
@config = @config['production'].to_options
@sleep_time = @config.delete(:sleep_time) || 20
def self.start
puts "Starting MailFetcherDaemon"
# Add your own receiver object below
@fetcher = Fetcher.create({:receiver => MailProcessor}.merge(@config))
...
所以我让它抓取新电子邮件,解析它们并从解析的数据创建资源。 但是当它尝试保存资源时,会引发异常。 这是因为脚本是自动分配开发环境的。 所以它使用我的开发数据库配置而不是生产环境(这是我想要的配置)。
我尝试用以下命令启动脚本:
rails-root$ RAILS_ENV=production; script/mail_fetcher start
但无济于事。 似乎当我加载environment.rb文件时,它只是默认为开发环境并从database.yml加载development.rb和开发数据库配置。
想法? 建议?
谢谢
I have a Rails application with a daemon that checks a mailbox for any new emails. I am using the Fetcher plugin for this task. The daemon file looks like this:
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment.rb'
class MailFetcherDaemon < Daemon::Base
@config = YAML.load_file("#{RAILS_ROOT}/config/mail.yml")
@config = @config['production'].to_options
@sleep_time = @config.delete(:sleep_time) || 20
def self.start
puts "Starting MailFetcherDaemon"
# Add your own receiver object below
@fetcher = Fetcher.create({:receiver => MailProcessor}.merge(@config))
...
So I have it grab the new emails, parse them and create a resource from the parsed data. But when it tries to save the resource an exception is thrown. This is because the script is automatically assigned the development environment. So it is using my development database configuration instead of the production environment (which is the config that I want).
I have tried starting the script with:
rails-root$ RAILS_ENV=production; script/mail_fetcher start
but to no avail. It seems like when I load the environment.rb file it just defaults to the development environment and loads development.rb and the development database configuration from database.yml.
Thoughts? Suggestions?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这在我的应用程序中有效,我看到的唯一区别是没有分号
This is working in my app, the only difference I see is no semi-colon
所以当你说
你的意思是
So when you say
do you mean
您可以尝试将其添加到脚本中:
或者,将其添加到命令行也可能有效。
You might try adding this to your script:
Alternatively, it might work to add it to the command line.