简体   繁体   English

delay_job在回形针上不起作用

[英]delayed_job not working on paperclip

I have this simply method that check against a URL existence and if not present try to create the photo object. 我有这个简单的方法来检查URL是否存在,如果不存在,请尝试创建照片对象。

 def create_profile_photo(user_id,image_url)
   if Photo.find_by_external_url(image_url).blank?
     profile_photo = Photo.new
     profile_photo.user_id = user_id
     profile_photo.picture_from_url(image_url)
     profile_photo.save
   end   
 end

# Photo.rb
def picture_from_url(url)
  self.external_url = url
  self.attachment = URI.parse(clean_url)
end

It does work. 确实有效。 But when I try to launch the method using delayed_job It does not work. 但是当我尝试使用delayed_job启动该方法时,它不起作用。

ruby-1.9.2-p290 :085 > MyClass.new.delay.create_profile_photo(347,'http://www.google.com/images/srpr/logo3w.png')
(0.4ms)  COMMIT
 => #<Delayed::Backend::ActiveRecord::Job id: 42, priority: 0, attempts: 0, handler: "--- !ruby/object:Delayed::ProfileableMethod\nobject:...", last_error: nil, run_at: "2012-12-08 21:40:06", locked_at: nil, failed_at: nil, locked_by: nil, queue: nil, created_at: "2012-12-08 21:40:06", updated_at: "2012-12-08 21:40:06"> 
ruby-1.9.2-p290 :085 > Photo.count
   (0.3ms)  SELECT COUNT(*) FROM "photos" 
=> 0

Any idea? 任何想法?

Of course there's no Photo instance in the photos table. 当然,在photos表中没有Photo实例。 According to your console, all you did was queue the job up. 根据您的控制台,您所做的只是将工作排队。

Unless you have a DJ worker running, you can't expect the DJ queue to be processed. 除非您正在运行DJ工作人员,否则您将无法期望DJ队列得到处理。 If the DJ queue isn't processed, you can't expect queued jobs to run. 如果未处理DJ队列,则不能期望排队的作业运行。 If the queued job hasn't been run, you can't expect photos to have any new records. 如果尚未运行排队的作业,则不能指望photos具有任何新记录。

Run the command below and you'll see the job still queued up waiting to be run. 运行下面的命令,您将看到作业仍在排队等待运行。

Delayed::Job.find(42)

In development, run the following to start a DJ daemon. 在开发中,运行以下命令以启动DJ守护程序。

script/delayed_job

And finally, as @simonmorley suggested, make sure you kill and restart the daemon between code changes in order for the jobs to be processed by an up-to-date version of your application. 最后,按照@simonmorley的建议,请确保在代码更改之间终止并重新启动守护程序,以使作业由应用程序的最新版本处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM