lardawge/carrierwave_backgrounder

How can I get all job ids to track their status when uploading multiple pictures?

Closed this issue · 2 comments

Hi there. I need to upload multiple pictures at once in the background. However, I also need to track their status (I'm using the sidekiq-status gem for it). I need to store the job ids though in order to do so. Since carrierwave_backgrounder encapsulates this functionality, I need to know how can I store all the job_ids in an array in the controller action through which they're triggered.

@lardawge Can you please help me out here? I can't decipher how to capture the id for jobs triggered by an action. Thanks!

Way outdated but worth documenting.

You could override enqueue_#{column}_background_job in your model and call super on it setting a variable. This will return the job_id.

# model

mount_uploader :avatar, AvatarUploader
process_in_background :avatar, MyStatusWorker

private 

def enqueue_avatar_background_job
  job_id = super
  # do something with the job_id
end

The second part of this would be to override the worker so that you can inject the methods from sidekiq-status.

class MyStatusWorker < ::CarrierWave::Workers::ProcessAsset # switch this out for StoreAsset if needed
  include Sidekiq::Status::Worker
end