1
votes

I'm using Carrierwave-Backgrounder with Sidekiq to process User icons. Unfortunately, every time I update the User model it triggers CarrierWave::Workers::ProcessAsset to process the existing image. Is there a way to make the backgrounder run only if the User has an icon or changes an existing one? I've tried everything...

user.rb

class User < ActiveRecord::Base  
  mount_uploader :icon, IconUploader
  process_in_background :icon

icon_uploader.rb

class IconUploader < CarrierWave::Uploader::Base
  include ::CarrierWave::Backgrounder::Delay

INFO: Booting Sidekiq 2.14.1 using redis://localhost:6379/0 with options
INFO: Running in ruby 2.0.0p247 (2013-06-27 revision 41674)
INFO: Starting processing, hit Ctrl-C to stop

CarrierWave::Workers::ProcessAsset JID-f2c19a1e33e83be2dce31961 INFO: start CarrierWave::Workers::ProcessAsset JID-f2c19a1e33e83be2dce31961 INFO: done: 0.733 sec CarrierWave::Workers::ProcessAsset JID-a497e66f54609f76678db81a INFO: start CarrierWave::Workers::ProcessAsset JID-a497e66f54609f76678db81a INFO: done: 0.32 sec CarrierWave::Workers::ProcessAsset JID-576dd9a036323e700e86860c INFO: start CarrierWave::Workers::ProcessAsset JID-576dd9a036323e700e86860c INFO: done: 0.588 sec

1
There might be something in your User model which is "dirtying" the icon attribute.davogones

1 Answers

1
votes

As gems go, carrierwave-backgrounder is pretty simple. They only enqueue a job if the field has been "updated", where "updated" is defined as any of the following being true:

  1. avatar_changed?
  2. previous_changes.has_key?(:avatar)
  3. remote_avatar_url.present?
  4. avatar_cache.present?

1 & 2 apply if you're changing the avatar through assignment, 3 applies if you're letting people paste in URLs, and 4 applies if you're caching changes between form reloads.

If you're absolutely certain that none of those are the case and you're still seeing jobs on every save, you may want to create an issue on their issue tracker.