微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – 带Rails的自定义守护程序3

我正在尝试创建加载Rails环境的自定义守护程序.
我的环境如下:
红宝石1.9.2-P180
导轨3.0.5

我做了以下:

– 安装守护进程宝石

在这里找到的安装的daemon_generator插件
https://github.com/dougal/daemon_generator

生成守护进程:rails生成守护进程监听器

所有这一切都很好.当我运行守护进程时,它可以运行.

但是,一旦我尝试访问一个活动的记录对象,就像试图检索一个用户一样,它会爆炸.

*** below you find the most recent exception thrown,this will be likely (but not certainly) the exception that made the application exit abnormally ***
#<NameError: method `recognize' not defined in Rack::Mount::RouteSet>
*** below you find all exception objects found in memory,some of them may have been thrown in your application,others may just be in memory because they are standard exceptions ***
#<NoMemoryError: Failed to allocate memory>
#<SystemStackerror: stack level too deep>
#<fatal: exception reentered>
#<NoMethodError: undefined method `eq' for nil:NilClass>
#<NameError: method `recognize' not defined in Rack::Mount::RouteSet>

关于如何创建加载Rails 3.0.5的守护进程的任何想法?

解决方法

我喜欢滚动我自己的rails守护进程控制器.这是一个简单的例子,适用于大多数情况:

脚本/守护

#!/usr/bin/env ruby
require 'rubygems'
require 'daemons'

ENV["APP_ROOT"] ||= File.expand_path("#{File.dirname(__FILE__)}/..")
ENV["RAILS_ENV_PATH"] ||= "#{ENV["APP_ROOT"]}/config/environment.rb"

script = "#{ENV["APP_ROOT"]}/daemons/#{ARGV[1]}"

Daemons.run(script,dir_mode: :normal,dir: "#{ENV["APP_ROOT"]}/tmp/pids")

守护进程/ your_daemon_script.rb

require ENV["RAILS_ENV_PATH"]
loop { 
  ... your code ...
}

您可以使用以下命令来控制您的deamons:

script/daemon run your_daemon_script.rb
script/daemon start your_daemon_script.rb
script/daemon stop your_daemon_script.rb

这使我能够轻松添加新的守护进程,如果需要,我可以轻松地在每个脚本中加载rails.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐