chaps-io / gush

Fast and distributed workflow runner using ActiveJob and Redis
MIT License
1.03k stars 103 forks source link

Not able to access Rails project classes in jobs #16

Closed jalberto closed 7 years ago

jalberto commented 8 years ago

Whats the recommended way to run Gush in a Rails (api) project?

I'm trying:

APP_PATH = File.expand_path('./config/application', __FILE__)
require_relative './config/boot'
require_relative './config/application'

Dir[Rails.root.join("app/workflows/**/*.rb")].each do |file|
  require file
end
Dir[Rails.root.join("app/jobs/**/*.rb")].each do |file|
  require file
end

But is not working properly, every job just fail on start because I'm using clasess of my rails proj in the jobs (like Services or Models).

Stack:

Any suggestion?

pokonski commented 8 years ago

Can you try the way sidekiq does it:

require File.expand_path("#{options[:require]}/config/application.rb")
::Rails::Application.initializer "gush.eager_load" do
  ::Rails.application.config.eager_load = true
end

?

where options[:require] is the path to your app.

Reasoning: https://github.com/mperham/sidekiq/issues/1791

jalberto commented 8 years ago

Thanks for the suggestion, but I have same result :(

I also tried several variants requiring environment.rb (to your suggestion and to mine) but somethign weird happens then, The jobs are enqueded (I can see after reload it) but the gush workers are not triggered.

This is really blocking me to use gush.

Something I don't understand is, if gush jobs run inside a sidekiq worker, and sidekiq workers are working well, Why this happens?

Thanks in advance

jalberto commented 8 years ago

For the record:

I tried to mimic the way binstubs works, bin/bundle, bin/rake, etc. have slight different ways to work, but none worked for me

badlamer commented 8 years ago

And I have same result :(

Rails 4.2.5

kakoni commented 8 years ago

This should work with rails >= 4 , adjust those requires accordingly

require './config/application'

::Rails::Application.initializer "gush.eager_load" do
  ::Rails.application.config.eager_load = true
end

require 'sidekiq/rails' #(well piggybagging on this..)
require './config/environment'
pokonski commented 7 years ago

Version 1.0 will have an example on how to load Rails projects correctly :)