socialpandas / sidekiq-superworker

Directed acyclic graphs of Sidekiq jobs
MIT License
438 stars 34 forks source link

Superworker namespace issues #23

Closed karloscodes closed 10 years ago

karloscodes commented 10 years ago

I have this code inside a rails engine:

Superworker.create(:AJob, :a_id, :data) do
  AWorker :a_id, :data do
    parallel do
      BWorker :a_id, :data
      CWorker :a_id, :data
      DWorker :a_id, :data
    end
    EWorker :a_id, :data
  end
end

The problem I'm facing is that the workers are under the engine namespace and Superworker does not understand MyEngine::AWorker notation, how can this be solved? Workers path was added to the autoload path using:

module MyEngine
class Engine < ::Rails::Engine
    isolate_namespace MyEngine

    ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '..', '..')
    config.autoload_paths << File.expand_path(File.join(ENGINE_RAILS_ROOT, 'app', 'workers'))

    require File.expand_path(File.join(ENGINE_RAILS_ROOT, 'app', 'jobs', 'superworkers'))
  end
end

What might be the problem?

karloscodes commented 10 years ago

Autooad path is like this instead of above!

config.autoload_paths << File.expand_path(File.join(ENGINE_RAILS_ROOT, 'app', 'workers', 'my_engine'))
tombenner commented 10 years ago

To use a namespaced worker in the DSL, you'll want to replace, for example, AWorker with MyEngine__AWorker. There's more information about this in #13.

This wasn't previously mentioned in the README, but I've added it. Let me know if that doesn't fix this for you. Thanks!

karloscodes commented 10 years ago

I’m using 0.1.8 and it is not working I’m getting uninitialized constant MyEngine__AWorker (NameError)

Should I need to grab github version or am I missing something?

I wonder if autoload path on the engine declaration should be changed by requires…

tombenner commented 10 years ago

Does the worker have any arguments passed to it in the DSL block? If it doesn't, be sure to add parentheses after it (as described here).

If that isn't the issue, you may be correct that autoloading isn't sufficient, and that explicit requires are necessary. If you could let me know whether requiring the workers before defining the superworker fixes this, that'd be great, as it might make sense to add support for autoloading into Sidekiq Superworker.

karloscodes commented 10 years ago

Doing manual requires solved the problem, so the issue was autoloading,

Thanks!

De: Tom Benner [mailto:notifications@github.com] Enviado el: Sunday, June 22, 2014 2:26 PM Para: socialpandas/sidekiq-superworker CC: Carlos Castellanos Asunto: Re: [sidekiq-superworker] Superworker namespace issues (#23)

Does the worker have any arguments passed to it in the DSL block? If it doesn't, be sure to add parentheses after it (as described here https://github.com/socialpandas/sidekiq-superworker#arguments ).

If that isn't the issue, you may be correct that autoloading isn't sufficient, and that explicit requires are necessary. If you could let me know whether requiring the workers before defining the superworker fixes this, that'd be great, as it might make sense to add support for autoloading into Sidekiq Superworker.

— Reply to this email directly or view it on GitHub https://github.com/socialpandas/sidekiq-superworker/issues/23#issuecomment-46788596 . https://github.com/notifications/beacon/1001834__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcxOTA4MDc1OSwiZGF0YSI6eyJpZCI6MzUyMzA5ODB9fQ==--08f12b06ec3d71933b388c15fc29ce48d30e72ad.gif