【问题标题】:Delaying image processing using CarrierWave and DelayedJob使用 CarrierWave 和 DelayedJob 延迟图像处理
【发布时间】:2015-03-12 21:54:04
【问题描述】:

我正在尝试在创建新产品和使用 CarrierWave 上传/调整图像大小的过程中使用 DelayedJob 实现后台进程(全部在 save 方法中完成)

我有一个页面,摄影师可以在其中上传新图片以及标题、描述等。

直到所有内容都成功处理后,新记录才会保存,因此当我尝试在“@photo.delay.save”行延迟处理时出现错误

def create
@photo = Photo.new(photo_params)
if @photo.delay.save
  flash[:notice] = "Your new photograph is being processed."
  redirect_to @photo
else
  flash[:notice] =  "Please check that all the fields were entered"
  render 'new'
end

结束

错误

job cannot be created for non-persisted record: #<Photo id: nil, title: "prod number 8526", created_at: nil, updated_at: nil, id_num: "jh878", year_taken: "2015", is_active: false, show_bw_conversion: false, format_id: 1, rotating_keyword: "picture", slug: nil, qty_sold: 0, photographer_id: 5, daily_deal: nil, default_mat: 1, default_frame: 1, description: "<p>This is the description3895</p>", qty_download: 0, film_type: "digital", image: nil>

这种策略是否可行,或者我应该让摄影师列出标题、描述等,以便干净地保存新记录,然后运行延迟作业以使用 Carrier Wave 上传/调整图像大小?

谢谢, 杰夫

【问题讨论】:

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


    【解决方案1】:

    需要先将照片行保存到数据库中,然后才能在延迟作业中引用它。

    我会让照片的文件上传部分与照片元数据完全分开。因此文件通过 ajax 发布(可能保存到 s3),然后 s3 文件名与表单中的其余元数据一起发布。

    另外,@photo.delay.save 无法工作,因为延迟作业的意义在于,该作业在稍后的某个时间点在其他进程中运行。您将无法在此控制器操作中访问稍后处理的结果。

    【讨论】:

    • @photo.save期间如何跳过图片上传过程?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多