lardawge/carrierwave_backgrounder

store_in_background with sidekiq not working

Closed this issue · 5 comments

I want to handle uploading user avatars to S3 in background, but for some reason it doesn't work for me.

This is my setup:

class AvatarUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  include CarrierWave::MiniMagick
  include ::CarrierWave::Backgrounder::Delay

  # Choose what kind of storage to use for this uploader:
  storage :fog

  process resize_to_fit: [800, 800]

  version :large_thumb do
    process resize_to_fit: [150, 150]
  end
end
# /config/initializers/carrierwave_backgrounder.rb

CarrierWave::Backgrounder.configure do |c|
  c.backend :sidekiq, queue: :carrierwave
end
# users_controller.rb

def user_params
    params.require(:user).permit(
      ..., :avatar, :avatar_cache, :remove_avatar, ...
    )
end
# sidekiq.yml

---
:queues:
  - carrierwave

I run sidekiq using the command:

bundle exec sidekiq

when I try to upload avatar for user with the following setting: (store_in_background)

#  avatar                 :string
#  avatar_processing      :boolean          default(FALSE), not null
#  avatar_tmp             :string

class User < ActiveRecord::Base

  mount_uploader :avatar, AvatarUploader
  store_in_background :avatar
  # process_in_background :avatar
  attr_accessor :avatar_cache
end

it doesn't seem to enqueue any jobs in the background in sidekiq and the avatar saving is done in-process and apparently it takes a long time. The avatar processing also does not seem to happen, as the user avatar version seems to return a url that implies that such a file doesn't exist.

But when I change the setting to: (process_in_background)

#  avatar                 :string
#  avatar_processing      :boolean          default(FALSE), not null
#  avatar_tmp             :string

class User < ActiveRecord::Base

  mount_uploader :avatar, AvatarUploader
  # store_in_background :avatar
  process_in_background :avatar
  attr_accessor :avatar_cache
end

The avatar upload happens in-process as expected and a sidekiq job is enqueued for processing the versions of the avatar. So this seems to work as expected.

carrierwave (0.10.0)
carrierwave_backgrounder (0.4.2)

Am I missing anything here ?

@sai92messy ,

Did you get any solution for this. I am also stuck here

No @grepruby I haven't found a solution for this yet.

Sorry for the delayed response. It looks to me like you are not starting sidekiq correctly. carrierwave is the queue name but it is not started.

bundle exec sidekiq -q carrierwave,2 -q default

Thanks. Adding the queue when starting sidekiq made it work 👍

@cesc1989 @lardawge Hi I hope you are doing greate can you please help me to understand when we use processing_in_background and
store_in_background these two fileds need to add using migration or anything else happening in under the hood.

avatar_tmp 
avatar_processing 

Thanks