开发者

How can I boot Rails 3 in a daemonized ruby script?

I am pulling email via pop into my Rails 3 application so i have a file called dropbox_receiver.rb in the rails lib directory.

This pulls in all email and calls DropBox.receive(email)

I can run this using rails/runner but when i run it from the daemon_controller.rb file i get the error

initialized constant Object::DropBox

How do i boot rails 3 in this script ?

Also h开发者_如何转开发ow do i log properly from this script to my production.log?


Put this at the top of your script:

ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'development'               
require File.expand_path(File.dirname(__FILE__) + "/../../config/environment"

That's for a script in app/controllers. You'll need to adjust the path to config/environment if your daemon is elsewhere.


Also, you're probably going to run into the issue of open files as described here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜