1

我已经配置了我的站点,以便它可以在后台自动呈现不同版本的视频。它实际上工作得很好。如果视频在三种不同的转码中成功,它将发送一封成功电子邮件。但是,如果它产生错误,它将发送失败电子邮件。我遇到的问题是我试图将 self 传递给 Action Mailer,以便我至少可以给出成功或失败的视频的名称。但是,似乎 self 为空。

模型

  def video_success(format, opts)
    VideoMailer.video_success(self).deliver
  end
  def video_rescue(format, opts)
    VideoMailer.video_error(self).deliver
  end

上传者

version :mp4 do
    process :encode_video => [:mp4, callbacks: {rescue: :video_rescue}  ]
    def full_filename(for_file)
      "#{File.basename(for_file, File.extname(for_file))}.mp4"
    end
end


version :webm do
    process :encode_video => [:webm, callbacks: { after_transcode: :video_success, rescue: :video_rescue }]
    def full_filename(for_file)
      "#{File.basename(for_file, File.extname(for_file))}.webm"
    end
end

关于如何实现这一点的任何想法?此外,如果有错误,最好返回生成的错误消息。

其次,每个用户模型都有一个电子邮件地址。上传视频的用户应该会收到电子邮件地址。但是,我在模型中使用 current_user 时遇到问题。我认为它也与后台程序有关,因为该信息不会传递给后台进程。

4

1 回答 1

2

I added a class method to the end of the background processor

process_in_background :video, ParanoidVideo

In the models directory, I created paranoid_video.rb and referenced the delivery of the mail. This way, the Carrierwave_Backgrounder is handling the success method instead of Carrierwave-Video.

class ParanoidVideo < ::CarrierWave::Workers::ProcessAsset
  def success(job)
    VideoMailer.video_backgrounder(job).deliver
  end
end

I ended up creating a new field in the database called last_updated_by and use this to return which user is being called. Granted, this is an extra call to the database when the user is being pulled, but I find that this is sufficient for my purposes. The background processor statically returns consistent handlers so I was able to just split the lines and gsub to get the ID. to_i will pull the first numerical value which is always the Video id in my case.

  def video_backgrounder(job)
    @job = job
    @video = Video.find_by_id(@job.handler.split("\n")[2].gsub("id: '","").to_i)
    @user = User.find_by_id(@video.last_updated_by)
    mail(:to => @user.email, :subject => "Video Transcoding Successful")
  end
于 2013-02-07T13:30:13.600 回答