lardawge/carrierwave_backgrounder

Process in background not working

JamesAndresCM opened this issue · 1 comments

Hi i'm trying to upload images in rails api, but this doesn't work

Uploader :

class ImgUploader < CarrierWave::Uploader::Base
  include ::CarrierWave::Backgrounder::Delay
  ...

Model :

class Character < ApplicationRecord
  mount_base64_uploader :img, ImgUploader
  process_in_background :img
  store_in_background :img
 ...

Response:

 Character Create (1.1ms)  INSERT INTO "characters" ("name", "bio", "img", "release", "created_at", "updated_at", "category_id", "img_processing", "img_tmp") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id"  [["name", "Ioioioioijejid"], ["bio", "Iojdeidjeiod"], ["img", nil], ["release", "2019-01-31"], ["created_at", "2019-01-30 18:25:17.863165"], ["updated_at", "2019-01-30 18:25:17.863165"], ["category_id", 2], ["img_processing", true], ["img_tmp", "1548872717-95937-0001-2213/file.png"]]
  ↳ app/controllers/api/v1/characters_controller.rb:20
   (1.2ms)  COMMIT
  ↳ app/controllers/api/v1/characters_controller.rb:20
   (0.3ms)  BEGIN
  ↳ /Users/snake/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/bundler/gems/carrierwave_backgrounder-2c7163af6a66/lib/backgrounder/support/backends.rb:34
  Delayed::Backend::ActiveRecord::Job Create (0.7ms)  INSERT INTO "delayed_jobs" ("handler", "run_at", "queue", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["handler", "--- !ruby/object:CarrierWave::Workers::StoreAsset\nklass: Character\nid: '67'\ncolumn: :img\n"], ["run_at", "2019-01-30 18:25:17.896440"], ["queue", "carrierwave"], ["created_at", "2019-01-30 18:25:17.896509"], ["updated_at", "2019-01-30 18:25:17.896509"]]
  ↳ /Users/snake/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/bundler/gems/carrierwave_backgrounder-2c7163af6a66/lib/backgrounder/support/backends.rb:34
   (0.8ms)  COMMIT

Img not update from img_tmp

¿any idea?

You should only be using either #process_in_background or #store_in_background. I would only recommend #store_in_background in the case where you have a shared tmp directory across your workers and web servers. I am actually going to remove it because it is confusing and not very useful.