gpt4 book ai didi

ruby-on-rails - 无法使用 Clockwork 启动 clock.rb 模块 - 来自 activesupport 的未定义方法

转载 作者:数据小太阳 更新时间:2023-10-29 07:39:48 24 4
gpt4 key购买 nike

我有一个网络应用需要做一些后台工作。我有一个 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 模块的代码是否有问题?

最佳答案

您需要将 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...]

关于ruby-on-rails - 无法使用 Clockwork 启动 clock.rb 模块 - 来自 activesupport 的未定义方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12747267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com