我的rails应用程序中有一个事件模型:
class Event < ApplicationRecord
...
end
我在时钟dyno上运行发条过程
require_relative 'boot'
require_relative 'environment'
require 'clockwork'
module Clockwork
every(10.seconds, 'xyz') do
Resque.enqueue(.......)
end
every(2.seconds, '.....') do
Resque.enqueue(.......)
end
end
这个clock.rb文件有一个resque作业,它以给定的节奏调用。当我在本地运行发条并在不同的终端中排队时它工作正常,但是当我在heroku上部署它时它失败了,因为我试图在我的clock.rb中需要environment.rb文件(我试图在heroku上部署而不需要环境但它引发了发条模块中的其他问题)。我不明白的部分是为什么它只是失败了event.rb?如果它在heroku上失败了,它也应该在本地失败。
错误如下:
2017-06-02T06:25:24.578369+00:00 app[clock.1]: /app/app/models/event.rb:1:in `<top (required)>': superclass mismatch for class Event (TypeError)
2017-06-02T06:25:24.578383+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:293:in `require'
2017-06-02T06:25:24.578384+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:293:in `block in require'
2017-06-02T06:25:24.578385+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:259:in `load_dependency'
2017-06-02T06:25:24.578385+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:293:in `require'
2017-06-02T06:25:24.578389+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:380:in `block in require_or_load'
2017-06-02T06:25:24.578389+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:37:in `block in load_interlock'
2017-06-02T06:25:24.578390+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.3/lib/active_support/dependencies/interlock.rb:12:in `block in loading'
2017-06-02T06:25:24.578391+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.3/lib/active_support/concurrency/share_lock.rb:150:in `exclusive'
2017-06-02T06:25:24.578392+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.3/lib/active_support/dependencies/interlock.rb:11:in `loading'
2017-06-02T06:25:24.578393+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:37:in `load_interlock'
2017-06-02T06:25:24.578393+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:358:in `require_or_load'
2017-06-02T06:25:24.578397+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:336:in `depend_on'
2017-06-02T06:25:24.578398+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.3/lib/active_support/dependencies.rb:252:in `require_dependency'
2017-06-02T06:25:24.578399+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.0.3/lib/rails/engine.rb:476:in `block (2 levels) in eager_load!'
2017-06-02T06:25:24.578400+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.0.3/lib/rails/engine.rb:475:in `each'
2017-06-02T06:25:24.578400+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.0.3/lib/rails/engine.rb:475:in `block in eager_load!'
2017-06-02T06:25:24.578401+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.0.3/lib/rails/engine.rb:473:in `each'
2017-06-02T06:25:24.578402+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.0.3/lib/rails/engine.rb:473:in `eager_load!'
2017-06-02T06:25:24.578402+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.0.3/lib/rails/engine.rb:354:in `eager_load!'
2017-06-02T06:25:24.578403+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.0.3/lib/rails/application/finisher.rb:59:in `each'
2017-06-02T06:25:24.578404+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.0.3/lib/rails/application/finisher.rb:59:in `block in <module:Finisher>'
2017-06-02T06:25:24.578404+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.0.3/lib/rails/initializable.rb:30:in `instance_exec'
2017-06-02T06:25:24.578405+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.0.3/lib/rails/initializable.rb:30:in `run'
2017-06-02T06:25:24.578405+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.0.3/lib/rails/initializable.rb:55:in `block in run_initializers'
2017-06-02T06:25:24.578406+00:00 app[clock.1]: from /app/vendor/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
2017-06-02T06:25:24.578407+00:00 app[clock.1]: from /app/vendor/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
2017-06-02T06:25:24.578407+00:00 app[clock.1]: from /app/vendor/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
2017-06-02T06:25:24.578408+00:00 app[clock.1]: from /app/vendor/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
2017-06-02T06:25:24.578410+00:00 app[clock.1]: from /app/vendor/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `each'
2017-06-02T06:25:24.578411+00:00 app[clock.1]: from /app/vendor/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `call'
2017-06-02T06:25:24.578411+00:00 app[clock.1]: from /app/vendor/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
2017-06-02T06:25:24.578412+00:00 app[clock.1]: from /app/vendor/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
2017-06-02T06:25:24.578413+00:00 app[clock.1]: from /app/vendor/ruby-2.4.0/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
2017-06-02T06:25:24.578414+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.0.3/lib/rails/initializable.rb:54:in `run_initializers'
2017-06-02T06:25:24.578414+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.0.3/lib/rails/application.rb:352:in `initialize!'
2017-06-02T06:25:24.578416+00:00 app[clock.1]: from /app/config/environment.rb:5:in `<top (required)>'
2017-06-02T06:25:24.578417+00:00 app[clock.1]: from /app/config/clock.rb:2:in `require_relative'
2017-06-02T06:25:24.578417+00:00 app[clock.1]: from /app/config/clock.rb:2:in `<top (required)>'
2017-06-02T06:25:24.578420+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/clockwork-0.2.4/bin/clockwork:13:in `require'
2017-06-02T06:25:24.578421+00:00 app[clock.1]: from /app/vendor/bundle/ruby/2.4.0/gems/clockwork-0.2.4/bin/clockwork:13:in `<top (required)>'
2017-06-02T06:25:24.578421+00:00 app[clock.1]: from /app/vendor/bundle/bin/clockwork:17:in `load'
2017-06-02T06:25:24.578422+00:00 app[clock.1]: from /app/vendor/bundle/bin/clockwork:17:in `<main>'
答案 0 :(得分:0)
我遇到了完全相同的错误和情况 - Ruby,Rails,Clockwork。它只发生在生产中。我的解决方案是简单地将我的事件类重命名为external_event,一旦我这样做,那么一切都正常。最好这是一个糟糕的解决方案,但我认为这是因为发条所依赖的require / include结构有效地将其内部命名空间带入应用程序本身。