Does not get along with Carrierwave::Mounter class (when using Sidekiq)
ume-kun1015 opened this issue · 0 comments
ume-kun1015 commented
I just would like to know if I am missing something to let carrierwave gem upload files in background or is the gem that's causing this error.
The method store_in_background
does not work well with Carrierwave::Mounter
class
When you can afford time, could you please tell me what to do solve this error?
The error I am facing
[1] pry(#<Front::SharedFilesController>)> shared_file.save!
(0.3ms) BEGIN
Project Load (0.3ms) SELECT `projects`.* FROM `projects` WHERE `projects`.`id` = 1 LIMIT 1
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
(0.2ms) ROLLBACK
NoMethodError: undefined method `cache_name' for #<CarrierWave::Mounter:0x00007fdeab096af0>
bundler/gems/carrierwave_backgrounder-460394b0e2c0/lib/backgrounder/orm/base.rb:88:in `write_name_identifier'
Versions
carrierwave (1.2.2)
carrierwave_backgrounder (0.4.2)
Codes
class SharedFile < ApplicationRecord
mount_uploader :name, SharedFileUploader
store_in_background :name
end
shared_file_worker.rb
(sidekiq)
class SharedFileWorker
include Sidekiq::Worker
sidekiq_options queue: 'carrierwave'
def perform(name, user_id, project_id)
shared_file = SharedFile.new(
name: name, user_id: user_id,
project_id: project_id
)
begin
shared_file.save!
rescue => error
logger.debug "Uploading Failed: #{error}"
end
end
end
shared_file_uploader.rb
class SharedFileUploader < CarrierWave::Uploader::Base
include ::CarrierWave::Backgrounder::Delay
if Rails.env.production? || Rails.env.development?
storage :fog
else
storage :file
end
end
initializers/carrierwave_backgrounder.rb
CarrierWave::Backgrounder.configure do |config|
config.backend :sidekiq, queue: :carrierwave
end