4

我有一个需要做一些后台工作的网络应用程序。我有一个clock.rb文件,其中包含:

require 'clockwork'
include Clockwork

require './config/boot'
require './config/environment'

every(5.seconds, 'ticking.get') { Resque.enqueue(TickingJob) }
[...rest of the code irrelevant...]

当我尝试使用 启动文件时clockwork app/clock.rb,出现以下错误:

/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.0/lib/active_support/configurable.rb:31:in `config': undefined method `inheritable_copy' for #<Hash:0x000000012b3f08> (NoMethodError)
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.0/lib/active_support/configurable.rb:86:in `config'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.0/lib/active_support/configurable.rb:59:in `default_per_page='
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/kaminari-0.13.0/lib/kaminari/config.rb:35:in `block in <module:Kaminari>'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/kaminari-0.13.0/lib/kaminari/config.rb:9:in `configure'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/kaminari-0.13.0/lib/kaminari/config.rb:34:in `<module:Kaminari>'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/kaminari-0.13.0/lib/kaminari/config.rb:3:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/kaminari-0.13.0/lib/kaminari.rb:38:in `require'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/kaminari-0.13.0/lib/kaminari.rb:38:in `load_kaminari!'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/kaminari-0.13.0/lib/kaminari.rb:47:in `hook!'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/kaminari-0.13.0/lib/kaminari.rb:60:in `load!'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/kaminari-0.13.0/lib/kaminari.rb:73:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:68:in `require'
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:66:in `each'
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:66:in `block in require'
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:55:in `each'
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler/runtime.rb:55:in `require'
    from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.2.1/lib/bundler.rb:128:in `require'
    from /home/raph/public/[...]/config/application.rb:7:in `<top (required)>'
    from /home/raph/public/[...]/config/environment.rb:2:in `require'
    from /home/raph/public/[...]/config/environment.rb:2:in `<top (required)>'
    from /home/raph/public/[...]/app/clock.rb:5:in `require'
    from /home/raph/public/[...]/app/clock.rb:5:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/clockwork-0.4.0/bin/clockwork:12:in `require'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/clockwork-0.4.0/bin/clockwork:12:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/clockwork:19:in `load'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/clockwork:19:in `<main>'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `eval'
    from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'

关于“psych”的第一个错误似乎无关紧要(我每次都得到它,并且我确实重新安装了libyaml)。至于第二个,我不知道。模块的代码activesupport不好吗?

4

1 回答 1

0

您需要将include Clockwork行移至以下require行:

require 'clockwork'    
require './config/boot'
require './config/environment'

include Clockwork

every(5.seconds, 'ticking.get') { Resque.enqueue(TickingJob) }
[...rest of the code irrelevant...]
于 2013-08-13T19:41:34.063 回答