问题
I´m new to sidekiq. I tested a very basic example and it´s working fine. Now, inside my job, I would like to call a method that is in a library in my lib folder but I´m getting some errors related to paths.
First, I define the files and structure:
- I have created a worker in my-project/app/workers/hard-worker.rb
require 'sidekiq'
Sidekiq.configure_client do |config|
config.redis = {db:1}
end
Sidekiq.configure_server do |config|
config.redis = {db:1}
end
class HardWorker
include Sidekiq::Worker
def perform()
puts "Initializing availabilities integration..."
CustomService.getAvailabilities
end
end
This method CustomService.getAvailabilities
is in my-project/lib/custom_service.rb
This custom_service.rb requires some other files:
require 'photo_service'
require 'open-uri'
require 'RMagick'
require 'boat_utils_service'
class MMKService
def self.getAvailabilities()
do whatever
end
end
The point it that this library is called and currently working by the user interface in our web app GUI, so, should be used from both GUI and background jobs.
I´m running the worker like: bundle exec sidekiq -r ./hard_worker.rb
The problem is when I run the worker job: 1. I get error until I require library like: require '../../lib/custom_service.rb' 2. I get error in custom_service.rb file with the require libraries. `require': cannot load such file -- photo_service (LoadError)
What am I missing? Do I need to update all my require paths?
来源:https://stackoverflow.com/questions/61329524/sidekiq-calling-methods-in-library-files