Wednesday, 15 February 2012

ruby on rails - How can I set default_url_options for Sidekiq workers? -



ruby on rails - How can I set default_url_options for Sidekiq workers? -

i have sidekiq worker intended perform social actions (e.g.: pages on facebook). part of requires knowing url object beingness liked.

fortunately, rails 3 makes easy access app-specific routes including rails.application.routes.url_helpers in whatever class or module needs access path/url helper method.

the problem i'm running default url/port not accessible within sidekiq worker despite various attempts define them in development.rb or production.rb.

class facebook::likerecipeworker include sidekiq::worker include rails.application.routes.url_helpers sidekiq_options queue: :facebook def perform(recipe_id, user_id) recipe = recipe.find(recipe_id) user = user.find(user_id) if user.facebook_token api = koala::facebook::api.new(user.facebook_token) api.put_connections 'me', 'my_namespace:like', object: recipe_url(recipe) end end end

when recipe_url method access, argumenterror raised message:

argumenterror: missing host link to! please provide :host parameter, set default_url_options[:host], or set :only_path true

i know can specify default_url_options actioncontroller or actionmailer in environment-specific config files, e.g.:

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } config.action_controller.default_url_options = { host: 'localhost', port: 3000 }

however, these (rightfully) appear have no influence on sidekiq worker classes. how should go defining default_url_options these classes?

what did this:

in config file(s) (e.g. config/application.rb, config/production.db, etc.), have line sets default:

routes.default_url_options = { host: 'www.example.org' }

ruby-on-rails routing worker sidekiq

No comments:

Post a Comment