I have an event model in my rails app:
class Event < ApplicationRecord
...
end
I am running a clockwork process on clock dyno which has
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
This clock.rb file has a resque job that it calls at a given cadence. It works fine when I run the clockwork and queue in separate terminals locally but when I deploy it on heroku it fails because of me trying to require the environment.rb file in my clock.rb (I tried to deploy on heroku without requiring the environment but it raises other issues in Clockwork module). The part that I do not understand is that why is it just failing for event.rb? And if it does fail on heroku, it should have failed locally too.
The error looks like:
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>'
I ran into the exact same error and circumstances -- Ruby, Rails, Clockwork. It only happens in production. My solution was to simply rename my event class to external_event and once I did that then everything just worked. At best this is a crappy solution but I think it is because of the require / include structure that clockwork relies on which effectively bring its internal namespace into the app itself.