Sidekiq calling methods in library files

巧了我就是萌 提交于 2021-02-11 15:55:48

问题


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:

  1. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!