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

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 带Rails的自定义守护程序3前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建加载Rails环境的自定义守护程序.
我的环境如下:
红宝石1.9.2-P180
导轨3.0.5

我做了以下:

– 安装守护进程宝石

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

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

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

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

  1. *** below you find the most recent exception thrown,this will be likely (but not certainly) the exception that made the application exit abnormally ***
  2. #<NameError: method `recognize' not defined in Rack::Mount::RouteSet>
  3. *** 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 ***
  4. #<NoMemoryError: Failed to allocate memory>
  5. #<SystemStackError: stack level too deep>
  6. #<fatal: exception reentered>
  7. #<NoMethodError: undefined method `eq' for nil:NilClass>
  8. #<NameError: method `recognize' not defined in Rack::Mount::RouteSet>

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

解决方法

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

脚本/守护

  1. #!/usr/bin/env ruby
  2. require 'rubygems'
  3. require 'daemons'
  4.  
  5. ENV["APP_ROOT"] ||= File.expand_path("#{File.dirname(__FILE__)}/..")
  6. ENV["RAILS_ENV_PATH"] ||= "#{ENV["APP_ROOT"]}/config/environment.rb"
  7.  
  8. script = "#{ENV["APP_ROOT"]}/daemons/#{ARGV[1]}"
  9.  
  10. Daemons.run(script,dir_mode: :normal,dir: "#{ENV["APP_ROOT"]}/tmp/pids")

守护进程/ your_daemon_script.rb

  1. require ENV["RAILS_ENV_PATH"]
  2. loop {
  3. ... your code ...
  4. }

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

  1. script/daemon run your_daemon_script.rb
  2. script/daemon start your_daemon_script.rb
  3. script/daemon stop your_daemon_script.rb

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

猜你在找的Ruby相关文章