zhong icon indicating copy to clipboard operation
zhong copied to clipboard

Best way to run Rails classes / jobs

Open dmitrypol opened this issue 6 years ago • 1 comments

I love the idea of this gem.
In my config/initializers/zhong.rb I did:

Zhong.schedule do
  every 5.seconds, 'MyJob' do
    MyJob.perform_later
  end
end

However when I run zhong I get MyJob failed: uninitialized constant MyJob . MyJob is located in app/jobs/...

I can do hacky things to load but has anyone tried this and hopefully come up w a better solution? What would be the best way to autoload Rails classes?

dmitrypol avatar Jan 02 '18 18:01 dmitrypol

Something like this will do

require 'sidekiq'
...
Dir['app/workers/**/*'].select{|file_name| file_name.end_with? '.rb'}.each {|f| require f }

Basically, you don't need the whole app to be able to enqueue a job. The sample above is Sidekiq specific, but you get the idea

ivanovv avatar May 01 '19 17:05 ivanovv