Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best way to run Rails classes / jobs #27

Open
dmitrypol opened this issue Jan 2, 2018 · 1 comment
Open

Best way to run Rails classes / jobs #27

dmitrypol opened this issue Jan 2, 2018 · 1 comment

Comments

@dmitrypol
Copy link

dmitrypol commented Jan 2, 2018

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 dmitrypol changed the title Best way to run Ruby classes / jobs Best way to run Ruby classes / Rails jobs Jan 2, 2018
@dmitrypol dmitrypol changed the title Best way to run Ruby classes / Rails jobs Best way to run Rails classes / jobs Jan 2, 2018
@ivanovv
Copy link

ivanovv commented May 1, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants