具有延迟作业的Carrierwave背景资料上传图像时没有此类文件或目录@ rb_sysopen

时间:2015-06-06 06:45:05

标签: ruby-on-rails-4 background carrierwave delayed-job

我在Digital Ocean Centos Nginx盒子上运行Rails 4.1.2应用程序。

我试图让carrierwave背景资料在后台存储图像,但是每次执行作业时我都会收到以下错误:

--- !ruby/struct:CarrierWave::Workers::StoreAsset
klass: Item
id: '40'
column: :main_image

No such file or directory @ rb_sysopen - /var/www/marketplace_v2/releases/20150603150220/tmp/uploads/1433571984-17438-0890/ie8-fine.jpg
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/carrierwave_backgrounder-0.4.1/lib/backgrounder/workers/store_asset.rb:16:in `initialize'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/carrierwave_backgrounder-0.4.1/lib/backgrounder/workers/store_asset.rb:16:in `open'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/carrierwave_backgrounder-0.4.1/lib/backgrounder/workers/store_asset.rb:16:in `perform'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/backend/base.rb:94:in `block in invoke_job'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in `block in initialize'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in `execute'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:40:in `run_callbacks'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/backend/base.rb:91:in `invoke_job'
(eval):3:in `block in invoke_job_with_newrelic_transaction_trace'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/newrelic_rpm-3.9.9.275/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:366:in `perform_action_with_newrelic_trace'
(eval):2:in `invoke_job_with_newrelic_transaction_trace'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:204:in `block (2 levels) in run'
/home/deployer/.rbenv/versions/2.1.2/lib/ruby/2.1.0/timeout.rb:91:in `block in timeout'
/home/deployer/.rbenv/versions/2.1.2/lib/ruby/2.1.0/timeout.rb:101:in `call'
/home/deployer/.rbenv/versions/2.1.2/lib/ruby/2.1.0/timeout.rb:101:in `timeout'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:204:in `block in run'
/home/deployer/.rbenv/versions/2.1.2/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:203:in `run'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:280:in `block in reserve_and_run_one_job'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in `block in initialize'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in `execute'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:40:in `run_callbacks'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:280:in `reserve_and_run_one_job'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:187:in `block in work_off'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:186:in `times'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:186:in `work_off'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:150:in `block (4 levels) in start'
/home/deployer/.rbenv/versions/2.1.2/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:149:in `block (3 levels) in start'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in `block in initialize'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in `execute'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:40:in `run_callbacks'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:148:in `block (2 levels) in start'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:147:in `loop'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:147:in `block in start'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/plugins/clear_locks.rb:7:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:79:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:79:in `block (2 levels) in add'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in `block in initialize'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:79:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:79:in `block in add'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in `execute'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:40:in `run_callbacks'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:146:in `start'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/command.rb:124:in `run'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/command.rb:112:in `block in run_process'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/daemons-1.2.2/lib/daemons/application.rb:265:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/daemons-1.2.2/lib/daemons/application.rb:265:in `block in start_proc'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/daemons-1.2.2/lib/daemons/daemonize.rb:84:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/daemons-1.2.2/lib/daemons/daemonize.rb:84:in `call_as_daemon'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/daemons-1.2.2/lib/daemons/application.rb:269:in `start_proc'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/daemons-1.2.2/lib/daemons/application.rb:295:in `start'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/daemons-1.2.2/lib/daemons/controller.rb:69:in `run'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/daemons-1.2.2/lib/daemons.rb:193:in `block in run_proc'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/daemons-1.2.2/lib/daemons/cmdline.rb:88:in `call'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/daemons-1.2.2/lib/daemons/cmdline.rb:88:in `catch_exceptions'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/daemons-1.2.2/lib/daemons.rb:192:in `run_proc'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/command.rb:110:in `run_process'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/command.rb:91:in `block in daemonize'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/command.rb:89:in `times'
/var/www/marketplace_v2/shared/bundle/ruby/2.1.0/gems/delayed_job-4.0.6/lib/delayed/command.rb:89:in `daemonize'
bin/delayed_job:5:in `<main>'

奇怪的是,错误顶行报告的图像确实存在。它似乎不是一个权限的东西,因为我已经尝试将其设置为777进行实验。

如果没有载波背景,图像处理工作正常,则会上传所有内容并创建正确的版本。

我在这里遗漏了什么或者误解了设置?

我目前的代码如下:

# encoding: utf-8

class ItemImageUploader < CarrierWave::Uploader::Base
  include ::CarrierWave::Backgrounder::Delay
  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  include CarrierWave::MiniMagick
  # include CarrierWave::ImageOptimizer

  def store_dir
    "#{Rails.root}/public/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end


  # Create different versions of your uploaded files:
  version :thumb do
    process :resize_to_limit => [50, 50]
  end

  version :gallery do
    process :resize_to_limit => [300, 300]
  end

  version :large_image do
    process :resize_to_limit => [700, 400]
  end

  # Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like this:
  def extension_white_list
    %w(jpg jpeg gif png)
  end

end

carrierwave.rb

# config/initializers/carrierwave.rb
CarrierWave.configure do |config|
  config.fog_credentials = {
    # Configuration for Amazon S3 should be made available through an Environment variable.
    # For local installations, export the env variable through the shell OR
    # if using Passenger, set an Apache environment variable.
    #
    # In Heroku, follow http://devcenter.heroku.com/articles/config-vars
    #
    # $ heroku config:add S3_KEY=your_s3_access_key S3_SECRET=your_s3_secret S3_REGION=eu-west-1 S3_ASSET_URL=http://assets.example.com/ S3_BUCKET_NAME=s3_bucket/folder

    # Configuration for Amazon S3
    :provider              => 'AWS',
    :aws_access_key_id     => ENV['AWS_ACCESS_KEY_ID'],
    :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
    :region                => ENV['AWS_REGION']
  }

  config.enable_processing = false

  # For testing, upload files to local `tmp` folder.
  if Rails.env.test? || Rails.env.cucumber?
    config.storage = :file
    config.enable_processing = false
    config.root = "#{Rails.root}/tmp"
  elsif Rails.env.development?
    config.storage = :file
  else
    # config.storage = :fog
    config.storage = :file
  end

  # config.cache_dir = "#{Rails.root}/tmp/uploads"                  # To let CarrierWave work on heroku
  config.fog_directory    = ENV['S3_BUCKET_NAME']
end

item.rb的

class Item < ActiveRecord::Base
  require 'acts-as-taggable-on'
  acts_as_taggable
  acts_as_taggable_on :location
  belongs_to :user
  has_many :categories
  has_many :extra_item_images

  validates :title, :price, :description, presence: true

  mount_uploader :main_image, ItemImageUploader
  store_in_background :main_image
  # process_in_background :main_image
  accepts_nested_attributes_for :extra_item_images
end

我完全迷失了,一直让我走了几天,并在谷歌上尽我所能,所以任何帮助都会非常感激。

最后一点信息。来自gemfile.lock

carrierwave (0.10.0)
  activemodel (>= 3.2.0)
  activesupport (>= 3.2.0)
  json (>= 1.7)
  mime-types (>= 1.16)
carrierwave-imageoptimizer (1.2.1)
  carrierwave (~> 0.8)
  image_optimizer (~> 1.2)
carrierwave_backgrounder (0.4.1)
  carrierwave (~> 0.5)

0 个答案:

没有答案