lardawge/carrierwave_backgrounder

CarrierWave::Workers::StoreAsset NameError: uninitialized constant Attachment

Closed this issue · 1 comments

I could really use some help with this issue. I've scoured the web and tried everything I can think of, but I can't fix this.

I have an Attachment model with the following code:

class Attachment < ApplicationRecord
  include Indestructible
  include FileType
  
  belongs_to :attachable, polymorphic: true
  mount_uploader :file, FileUploader
  store_in_background :file

  attr_accessor :width, :height

  before_save :direct_upload

  def is_image?
    extensions = %w(jpg jpeg gif png tiff bmp)
    extensions.include? self.extension
  end
  
  def extension
    self.file.try(:extension).try(:downcase)
  end

  def belongs_to_foto?
    self.attachable_type == "Photo"
  end

  protected

    # Skipping damn carrierwave_backgrounder when .pdf 
    def direct_upload
      self.process_file_upload = true if self.extension == 'pdf'
    end

end

I keep getting this issue on my resque log:

Screen Shot 2020-03-06 at 1 45 41 PM

The file ends up getting saved locally at uploads/tmp, but never gets cleared from here and saved to s3 like it should with store_in_background. The strange thing is that this bug happens randomly. It works fine maybe 30-50% of the time and gets saved to s3, but most of the time I get this error and it gets stuck in my local server storage. Which is a huge issue as you can imagine. We get a lot of image uploads in our app.

What could be causing this? I will really appreciate any help or comments, we've had this issue for months. Thanks.

If you are running in an environment where the tmp directory is not shared, when the background job fires, the file will not be there. This seems to be the likely case here. Sorry for the late reply... hope you solved it.