carrierwave_backgrounder 在 Rails 5.2 asset_tmp 无
carrierwave_backgrounder in Rails 5.2 asset_tmp nil
我在表单上有一个图片上传器,无需后台处理即可正常上传图片。自从转移到 Heroku 后,较大的源图像经常超时,所以我希望将其转移到后台作业。为此,我查看了 carrierwave_backgrounder
,因为它似乎涵盖了我需要的内容。
我找到了 carrierwave_backgrounder
的一个分支,并将其分支到我自己的存储库中。为了让它在 5.2 中工作,作者说他必须对路径进行硬编码 (https://github.com/lardawge/carrierwave_backgrounder/issues/282, https://github.com/lardawge/carrierwave_backgrounder/issues/280)
这在 store_in_background
上失败了。 运行 只是 process_in_background
在开发中生成本地处理的图像,但它们不会上传到 S3。
有问题的模型字段是 issue.image
,这是它在 issue.rb
中的安装方式:
# Image attachment via Carrierwave
mount_uploader :image, ImageUploader
process_in_background :image
store_in_background :image
attr_accessor :image_cache
这是输出错误:
2019-02-24T01:05:33.168Z 43666 TID-oxnydp4bq CarrierWave::Workers::StoreAsset JID-83163770b014d37186118cf9 INFO: start
2019-02-24T01:05:33.545Z 43666 TID-oxnydp4bq CarrierWave::Workers::StoreAsset JID-83163770b014d37186118cf9 INFO: fail: 0.377 sec
2019-02-24T01:05:33.545Z 43666 TID-oxnydp4bq WARN: {"context":"Job raised exception","job":{"class":"CarrierWave::Workers::StoreAsset","args":["Issue","6355","image"],"queue":"carrierwave","retry":true,"jid":"83163770b014d37186118cf9","created_at":1550970333.167957,"enqueued_at":1550970333.168011},"jobstr":"{\"class\":\"CarrierWave::Workers::StoreAsset\",\"args\":[\"Issue\",\"6355\",\"image\"],\"queue\":\"carrierwave\",\"retry\":true,\"jid\":\"83163770b014d37186118cf9\",\"created_at\":1550970333.167957,\"enqueued_at\":1550970333.168011}"}
2019-02-24T01:05:33.545Z 43666 TID-oxnydp4bq WARN: TypeError: no implicit conversion of nil into String
2019-02-24T01:05:33.545Z 43666 TID-oxnydp4bq WARN: /Users/jathayde/Development/Meticulous/carrierwave_backgrounder/lib/backgrounder/workers/store_asset_mixin.rb:40:in `join'
这是我本地版本 gem 中 store_asset_mixin.rb
方法的相关方法。错误中提到的第40行是以@tmp_directory
:
开头的
def store_directories(record)
asset, asset_tmp = record.send(:"#{column}"), record.send(:"#{column}_tmp")
cache_directory = File.expand_path(asset.cache_dir, asset.root)
# @cache_path = File.join(cache_directory, asset_tmp)
# # XXX Hardcoded our path here... not ideal..
@cache_path = open("https://patchvault.s3.amazonaws.com/uploads/tmp/#{asset_tmp}")
@tmp_directory = File.join(cache_directory, asset_tmp.split("/").first)
end
所以 asset_tmp
是 ""
,但资产但我不知道为什么。用 debugger
单步执行它似乎 record.image 存在,但是 record.image_tmp 列是空的,record.image_cache 是 nil。
不太确定它是否对您有帮助,但我过去所做的:基本上我已经创建了一个新的工作人员,同时完成了这两项工作。说不定也能给你带来一些启发。
型号:
store_in_background :photo, StoreTmpAndProcessWorker
工人:
class StoreTmpAndProcessWorker < ::CarrierWave::Workers::StoreAsset
sidekiq_options retry: 1
def perform(*args)
Chewy.strategy(:atomic) do
record = super(*args)
::CarrierWave::Workers::ProcessAsset.new.perform(*args)
photo = Photo.find_by(id: args[1])
if photo
scheme = case Rails.env
when 'production' then 'https'
when 'staging' then 'http'
end
ActionCable.server.broadcast "gallery_#{photo.photable_id}_channel",
url: BasePresenter.urlify(photo.photo.scaled.url, scheme: scheme), id: photo.id
end
end
end
end
我也对我的叉子做了一些改动,但没什么特别的:https://github.com/igorkasyanchuk/carrierwave_backgrounder。我的应用程序适用于 Rails 5.2.
我在表单上有一个图片上传器,无需后台处理即可正常上传图片。自从转移到 Heroku 后,较大的源图像经常超时,所以我希望将其转移到后台作业。为此,我查看了 carrierwave_backgrounder
,因为它似乎涵盖了我需要的内容。
我找到了 carrierwave_backgrounder
的一个分支,并将其分支到我自己的存储库中。为了让它在 5.2 中工作,作者说他必须对路径进行硬编码 (https://github.com/lardawge/carrierwave_backgrounder/issues/282, https://github.com/lardawge/carrierwave_backgrounder/issues/280)
这在 store_in_background
上失败了。 运行 只是 process_in_background
在开发中生成本地处理的图像,但它们不会上传到 S3。
有问题的模型字段是 issue.image
,这是它在 issue.rb
中的安装方式:
# Image attachment via Carrierwave
mount_uploader :image, ImageUploader
process_in_background :image
store_in_background :image
attr_accessor :image_cache
这是输出错误:
2019-02-24T01:05:33.168Z 43666 TID-oxnydp4bq CarrierWave::Workers::StoreAsset JID-83163770b014d37186118cf9 INFO: start
2019-02-24T01:05:33.545Z 43666 TID-oxnydp4bq CarrierWave::Workers::StoreAsset JID-83163770b014d37186118cf9 INFO: fail: 0.377 sec
2019-02-24T01:05:33.545Z 43666 TID-oxnydp4bq WARN: {"context":"Job raised exception","job":{"class":"CarrierWave::Workers::StoreAsset","args":["Issue","6355","image"],"queue":"carrierwave","retry":true,"jid":"83163770b014d37186118cf9","created_at":1550970333.167957,"enqueued_at":1550970333.168011},"jobstr":"{\"class\":\"CarrierWave::Workers::StoreAsset\",\"args\":[\"Issue\",\"6355\",\"image\"],\"queue\":\"carrierwave\",\"retry\":true,\"jid\":\"83163770b014d37186118cf9\",\"created_at\":1550970333.167957,\"enqueued_at\":1550970333.168011}"}
2019-02-24T01:05:33.545Z 43666 TID-oxnydp4bq WARN: TypeError: no implicit conversion of nil into String
2019-02-24T01:05:33.545Z 43666 TID-oxnydp4bq WARN: /Users/jathayde/Development/Meticulous/carrierwave_backgrounder/lib/backgrounder/workers/store_asset_mixin.rb:40:in `join'
这是我本地版本 gem 中 store_asset_mixin.rb
方法的相关方法。错误中提到的第40行是以@tmp_directory
:
def store_directories(record)
asset, asset_tmp = record.send(:"#{column}"), record.send(:"#{column}_tmp")
cache_directory = File.expand_path(asset.cache_dir, asset.root)
# @cache_path = File.join(cache_directory, asset_tmp)
# # XXX Hardcoded our path here... not ideal..
@cache_path = open("https://patchvault.s3.amazonaws.com/uploads/tmp/#{asset_tmp}")
@tmp_directory = File.join(cache_directory, asset_tmp.split("/").first)
end
所以 asset_tmp
是 ""
,但资产但我不知道为什么。用 debugger
单步执行它似乎 record.image 存在,但是 record.image_tmp 列是空的,record.image_cache 是 nil。
不太确定它是否对您有帮助,但我过去所做的:基本上我已经创建了一个新的工作人员,同时完成了这两项工作。说不定也能给你带来一些启发。
型号:
store_in_background :photo, StoreTmpAndProcessWorker
工人:
class StoreTmpAndProcessWorker < ::CarrierWave::Workers::StoreAsset
sidekiq_options retry: 1
def perform(*args)
Chewy.strategy(:atomic) do
record = super(*args)
::CarrierWave::Workers::ProcessAsset.new.perform(*args)
photo = Photo.find_by(id: args[1])
if photo
scheme = case Rails.env
when 'production' then 'https'
when 'staging' then 'http'
end
ActionCable.server.broadcast "gallery_#{photo.photable_id}_channel",
url: BasePresenter.urlify(photo.photo.scaled.url, scheme: scheme), id: photo.id
end
end
end
end
我也对我的叉子做了一些改动,但没什么特别的:https://github.com/igorkasyanchuk/carrierwave_backgrounder。我的应用程序适用于 Rails 5.2.