Processing does not seem to work in background job

214 views
Skip to first unread message

Anthony

unread,
Apr 17, 2017, 12:24:01 PM4/17/17
to Shrine
I'm trying to implement backgrounding with processing on my file uploaders. Backgrounding promote/delete seems to be working, but it seems like the process block does not get called. I am using sucker_punch in development. Here is the relevant code (I think). What might I be missing here?

shrine.rb
require "shrine"
require "shrine/storage/s3"

s3_audio_options = {
  access_key_id:     Rails.application.secrets.aws_audio_access_key_id,
  secret_access_key: Rails.application.secrets.aws_audio_secret_access_key,
  region:            Rails.application.secrets.aws_audio_region,
  bucket:            Rails.application.secrets.aws_audio_bucket,
}
s3_image_options = {
  access_key_id:     Rails.application.secrets.aws_audio_access_key_id,
  secret_access_key: Rails.application.secrets.aws_audio_secret_access_key,
  region:            Rails.application.secrets.aws_audio_region,
  bucket:            Rails.application.secrets.aws_audio_bucket,
}

Shrine.storages = {
  cache: Shrine::Storage::S3.new(prefix: "cache", upload_options: {acl: "public-read"}, **s3_audio_options),
  store: Shrine::Storage::S3.new(upload_options: {acl: "public-read"}, **s3_audio_options),
  image_cache: Shrine::Storage::S3.new(prefix: "image_cache", upload_options: {acl: "public-read"}, **s3_audio_options),
  image_store: Shrine::Storage::S3.new(prefix: "images", upload_options: {acl: "public-read"}, **s3_audio_options)
}

Shrine.plugin :activerecord
Shrine.plugin :direct_upload, allowed_storages: [:cache, :store, :image_cache, :image_store]
Shrine.plugin :restore_cached_data
Shrine.plugin :cached_attachment_data
Shrine.plugin :backgrounding

Shrine::Attacher.promote { |data| PromoteJob.perform_later(data) }
Shrine::Attacher.delete { |data| DeleteJob.perform_later(data) }


promote_job.rb
class PromoteJob < ActiveJob::Base
  def perform(data)
    Shrine::Attacher.promote(data)
  end
end


image_uploader.rb
class ImageUploader < Shrine
    plugin :default_storage, cache: :image_cache, store: :image_store
    plugin :remove_attachment
    plugin :processing

    process(:store) do |io|
      puts "Processing Done"
    end
end

Any help is appreciated!
-Anthony

Janko Marohnić

unread,
Apr 18, 2017, 3:54:54 AM4/18/17
to Anthony, Shrine
The setup looks correct, I don't have any ideas why it's not working. Could you create a self-contained example script that reproduces the problem, which can be copied into a file and can be run with `ruby bug.rb`? You can use the example template as a skeleton for the script.

Kind regards,
Janko

--
You received this message because you are subscribed to the Google Groups "Shrine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine+unsubscribe@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-shrine/cbb6ade3-5c42-47ac-8ea3-c0351ff3b752%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ant...@anthmatic.com

unread,
Apr 19, 2017, 1:49:40 PM4/19/17
to Shrine, ant...@anthmatic.com
Hi Janko,

It looks like my issue was caused by the Apartment gem. I'm fairly new to Ruby and it didn't dawn on me! Solved by adding the Apartment-Sidekiq gem.

Thanks so much for the reply and for creating/supporting Shrine!

Best,
-Anthony
Reply all
Reply to author
Forward
0 new messages