Carrierwave_backgrounder 和 delayed_job 无法在 Heroku 上运行:没有这样的文件或目录
Carrierwave_backgrounder and delayed_job not working on Heroku: No such file or directory
我正在使用 Carrierwave_backgrounder、delayed_job 和守护程序 gem 来处理在我的应用程序上上传多张图片,而不会立即从其他用户那里窃取带宽。工人将 运行 在我的本地开发服务器上没有问题。推送到我的 Heroku 暂存环境后,我在尝试完成作业时收到这些错误。
Delayed::Backend::ActiveRecord::Job Load (2.5ms) UPDATE "delayed_jobs" SET locked_at = '2015-10-28 23:46:15.299335', locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2015-10-28 23:46:15.298692' AND (locked_at IS NULL OR locked_at < '2015-10-28 19:46:15.298734') OR locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=20) RUNNING
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=20) RUNNING
VehicleImage Load (0.7ms) SELECT "vehicle_images".* FROM "vehicle_images" WHERE "vehicle_images"."id" = LIMIT 1 [["id", 91]]
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=20) FAILED (4 prior attempts) with Errno::ENOENT: No such file or directory - /app/public/uploads/tmp/1446075582-3-5608/Cancer_show_031.JPG
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=20) FAILED (4 prior attempts) with Errno::ENOENT: No such file or directory - /app/public/uploads/tmp/1446075582-3-5608/Cancer_show_031.JPG
(0.6ms) BEGIN
SQL (0.8ms) UPDATE "delayed_jobs" SET "attempts" = , "run_at" = , "locked_at" = , "locked_by" = , "updated_at" = WHERE "delayed_jobs"."id" = [["attempts", 5], ["run_at", "2015-10-28 23:56:45.308678"], ["locked_at", nil], ["locked_by", nil], ["updated_at", "2015-10-28 23:46:15.310442"], ["id", 20]]
(1.4ms) COMMIT
Delayed::Backend::ActiveRecord::Job Load (2.0ms) UPDATE "delayed_jobs" SET locked_at = '2015-10-28 23:46:15.318187', locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2015-10-28 23:46:15.317874' AND (locked_at IS NULL OR locked_at < '2015-10-28 19:46:15.317891') OR locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=21) RUNNING
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=21) RUNNING
VehicleImage Load (0.7ms) SELECT "vehicle_images".* FROM "vehicle_images" WHERE "vehicle_images"."id" = LIMIT 1 [["id", 92]]
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=21) FAILED (4 prior attempts) with Errno::ENOENT: No such file or directory - /app/public/uploads/tmp/1446075582-3-0693/Cancer_show_033.JPG
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=21) FAILED (4 prior attempts) with Errno::ENOENT: No such file or directory - /app/public/uploads/tmp/1446075582-3-0693/Cancer_show_033.JPG
(0.6ms) BEGIN
SQL (1.2ms) UPDATE "delayed_jobs" SET "attempts" = , "run_at" = , "locked_at" = , "locked_by" = , "updated_at" = WHERE "delayed_jobs"."id" = [["attempts", 5], ["run_at", "2015-10-28 23:56:45.322803"], ["locked_at", nil], ["locked_by", nil], ["updated_at", "2015-10-28 23:46:15.324371"], ["id", 21]]
(1.5ms) COMMIT
Delayed::Backend::ActiveRecord::Job Load (2.2ms) UPDATE "delayed_jobs" SET locked_at = '2015-10-28 23:46:15.329835', locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2015-10-28 23:46:15.329385' AND (locked_at IS NULL OR locked_at < '2015-10-28 19:46:15.329409') OR locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=22) RUNNING
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=22) RUNNING
VehicleImage Load (0.9ms) SELECT "vehicle_images".* FROM "vehicle_images" WHERE "vehicle_images"."id" = LIMIT 1 [["id", 93]]
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=22) FAILED (4 prior attempts) with Errno::ENOENT: No such file or directory - /app/public/uploads/tmp/1446075582-3-8474/Cancer_show_034.JPG
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=22) FAILED (4 prior attempts) with Errno::ENOENT: No such file or directory - /app/public/uploads/tmp/1446075582-3-8474/Cancer_show_034.JPG
(0.7ms) BEGIN
SQL (0.9ms) UPDATE "delayed_jobs" SET "attempts" = , "run_at" = , "locked_at" = , "locked_by" = , "updated_at" = WHERE "delayed_jobs"."id" = [["attempts", 5], ["run_at", "2015-10-28 23:56:45.336065"], ["locked_at", nil], ["locked_by", nil], ["updated_at", "2015-10-28 23:46:15.338022"], ["id", 22]]
(1.7ms) COMMIT
Delayed::Backend::ActiveRecord::Job Load (1.9ms) UPDATE "delayed_jobs" SET locked_at = '2015-10-28 23:46:15.344057', locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2015-10-28 23:46:15.343691' AND (locked_at IS NULL OR locked_at < '2015-10-28 19:46:15.343713') OR locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] 3 jobs processed at 62.5742 j/s, 3 failed
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] 3 jobs processed at 62.5742 j/s, 3 failed
Delayed::Backend::ActiveRecord::Job Load (1.4ms) UPDATE "delayed_jobs" SET locked_at = '2015-10-28 23:46:15.347046', locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2015-10-28 23:46:15.346718' AND (locked_at IS NULL OR locked_at < '2015-10-28 19:46:15.346737') OR locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
config/environments/production.rb
config.action_mailer.perform_deliveries = true
uploaders/image_uploader.rb
class ImageUploader < CarrierWave::Uploader::Base
include ::CarrierWave::Backgrounder::Delay
config/initializers/carrierwave_backgrounder.rb
CarrierWave::Backgrounder.configure do |c|
c.backend :delayed_job, queue: :carrierwave
# c.backend :resque, queue: :carrierwave
# c.backend :sidekiq, queue: :carrierwave
# c.backend :girl_friday, queue: :carrierwave
# c.backend :sucker_punch, queue: :carrierwave
# c.backend :qu, queue: :carrierwave
# c.backend :qc
end
vehicle_image.rb
class VehicleImage < ActiveRecord::Base
belongs_to :vehicle
mount_uploader :image, ImageUploader
process_in_background :image
store_in_background :image
def set_to_primary_and_save
VehicleImage.where(vehicle: vehicle).update_all(primary: false)
self.primary = true
save
end
end
感谢观看。
嗯,基本上你应该将图像上传到其他服务,如 AWS S3。因为 Heroku 不允许我们上传图片。您可以在此处阅读更多内容
我正在使用 Carrierwave_backgrounder、delayed_job 和守护程序 gem 来处理在我的应用程序上上传多张图片,而不会立即从其他用户那里窃取带宽。工人将 运行 在我的本地开发服务器上没有问题。推送到我的 Heroku 暂存环境后,我在尝试完成作业时收到这些错误。
Delayed::Backend::ActiveRecord::Job Load (2.5ms) UPDATE "delayed_jobs" SET locked_at = '2015-10-28 23:46:15.299335', locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2015-10-28 23:46:15.298692' AND (locked_at IS NULL OR locked_at < '2015-10-28 19:46:15.298734') OR locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=20) RUNNING
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=20) RUNNING
VehicleImage Load (0.7ms) SELECT "vehicle_images".* FROM "vehicle_images" WHERE "vehicle_images"."id" = LIMIT 1 [["id", 91]]
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=20) FAILED (4 prior attempts) with Errno::ENOENT: No such file or directory - /app/public/uploads/tmp/1446075582-3-5608/Cancer_show_031.JPG
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=20) FAILED (4 prior attempts) with Errno::ENOENT: No such file or directory - /app/public/uploads/tmp/1446075582-3-5608/Cancer_show_031.JPG
(0.6ms) BEGIN
SQL (0.8ms) UPDATE "delayed_jobs" SET "attempts" = , "run_at" = , "locked_at" = , "locked_by" = , "updated_at" = WHERE "delayed_jobs"."id" = [["attempts", 5], ["run_at", "2015-10-28 23:56:45.308678"], ["locked_at", nil], ["locked_by", nil], ["updated_at", "2015-10-28 23:46:15.310442"], ["id", 20]]
(1.4ms) COMMIT
Delayed::Backend::ActiveRecord::Job Load (2.0ms) UPDATE "delayed_jobs" SET locked_at = '2015-10-28 23:46:15.318187', locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2015-10-28 23:46:15.317874' AND (locked_at IS NULL OR locked_at < '2015-10-28 19:46:15.317891') OR locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=21) RUNNING
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=21) RUNNING
VehicleImage Load (0.7ms) SELECT "vehicle_images".* FROM "vehicle_images" WHERE "vehicle_images"."id" = LIMIT 1 [["id", 92]]
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=21) FAILED (4 prior attempts) with Errno::ENOENT: No such file or directory - /app/public/uploads/tmp/1446075582-3-0693/Cancer_show_033.JPG
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=21) FAILED (4 prior attempts) with Errno::ENOENT: No such file or directory - /app/public/uploads/tmp/1446075582-3-0693/Cancer_show_033.JPG
(0.6ms) BEGIN
SQL (1.2ms) UPDATE "delayed_jobs" SET "attempts" = , "run_at" = , "locked_at" = , "locked_by" = , "updated_at" = WHERE "delayed_jobs"."id" = [["attempts", 5], ["run_at", "2015-10-28 23:56:45.322803"], ["locked_at", nil], ["locked_by", nil], ["updated_at", "2015-10-28 23:46:15.324371"], ["id", 21]]
(1.5ms) COMMIT
Delayed::Backend::ActiveRecord::Job Load (2.2ms) UPDATE "delayed_jobs" SET locked_at = '2015-10-28 23:46:15.329835', locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2015-10-28 23:46:15.329385' AND (locked_at IS NULL OR locked_at < '2015-10-28 19:46:15.329409') OR locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=22) RUNNING
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=22) RUNNING
VehicleImage Load (0.9ms) SELECT "vehicle_images".* FROM "vehicle_images" WHERE "vehicle_images"."id" = LIMIT 1 [["id", 93]]
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=22) FAILED (4 prior attempts) with Errno::ENOENT: No such file or directory - /app/public/uploads/tmp/1446075582-3-8474/Cancer_show_034.JPG
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] Job CarrierWave::Workers::StoreAsset (id=22) FAILED (4 prior attempts) with Errno::ENOENT: No such file or directory - /app/public/uploads/tmp/1446075582-3-8474/Cancer_show_034.JPG
(0.7ms) BEGIN
SQL (0.9ms) UPDATE "delayed_jobs" SET "attempts" = , "run_at" = , "locked_at" = , "locked_by" = , "updated_at" = WHERE "delayed_jobs"."id" = [["attempts", 5], ["run_at", "2015-10-28 23:56:45.336065"], ["locked_at", nil], ["locked_by", nil], ["updated_at", "2015-10-28 23:46:15.338022"], ["id", 22]]
(1.7ms) COMMIT
Delayed::Backend::ActiveRecord::Job Load (1.9ms) UPDATE "delayed_jobs" SET locked_at = '2015-10-28 23:46:15.344057', locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2015-10-28 23:46:15.343691' AND (locked_at IS NULL OR locked_at < '2015-10-28 19:46:15.343713') OR locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
[Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] 3 jobs processed at 62.5742 j/s, 3 failed
2015-10-28T23:46:15+0000: [Worker(host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3)] 3 jobs processed at 62.5742 j/s, 3 failed
Delayed::Backend::ActiveRecord::Job Load (1.4ms) UPDATE "delayed_jobs" SET locked_at = '2015-10-28 23:46:15.347046', locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3' WHERE id IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE ((run_at <= '2015-10-28 23:46:15.346718' AND (locked_at IS NULL OR locked_at < '2015-10-28 19:46:15.346737') OR locked_by = 'host:7db12935-5a60-41b4-892b-934f088b53d5 pid:3') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *
config/environments/production.rb
config.action_mailer.perform_deliveries = true
uploaders/image_uploader.rb
class ImageUploader < CarrierWave::Uploader::Base
include ::CarrierWave::Backgrounder::Delay
config/initializers/carrierwave_backgrounder.rb
CarrierWave::Backgrounder.configure do |c|
c.backend :delayed_job, queue: :carrierwave
# c.backend :resque, queue: :carrierwave
# c.backend :sidekiq, queue: :carrierwave
# c.backend :girl_friday, queue: :carrierwave
# c.backend :sucker_punch, queue: :carrierwave
# c.backend :qu, queue: :carrierwave
# c.backend :qc
end
vehicle_image.rb
class VehicleImage < ActiveRecord::Base
belongs_to :vehicle
mount_uploader :image, ImageUploader
process_in_background :image
store_in_background :image
def set_to_primary_and_save
VehicleImage.where(vehicle: vehicle).update_all(primary: false)
self.primary = true
save
end
end
感谢观看。
嗯,基本上你应该将图像上传到其他服务,如 AWS S3。因为 Heroku 不允许我们上传图片。您可以在此处阅读更多内容