delayed_job - Performs not up to date code?

怎甘沉沦 提交于 2019-12-13 14:37:23

问题


I'm using delayed_job (tried both tobi's and collective_idea's) on site5.com shared hosting, with passenger as rails environment. I managed to make jobs done. However, it seems the plugin ignores any changes in a job class source code after first run. I have restarted the server on every change (touch tmp/restart.txt) but it still ignores it.

Example:

file: lib/xx_job.rb

class XxJob
  def perform
    Rails.logger.info "XX START"

    TempTest.delete_all

    i = 0
    10.times {
      i+=1
      TempTest.create(:name => "XXX")
      sleep(1)
    }

    Rails.logger.info "XX END"
  end
end

In a simple controller I call:

Delayed::Job.enqueue(XxJob.new)

Conclusions I have gathered:

  1. If I change xx_job.rb to xx_job1.rb - error on the controller
  2. If I change class XxJob to class XxJob1 - error on the controller
  3. If I delete all the perform method content - the old code old code is executed
  4. New .rb file with class and perform, enqueue this class - works perfectly
  5. If I change something in that new file's perform and run job again - old code is executed

Between every change I made a restart for the server. It seems like Passenger or something else saves class cache.

How can I delete this cache? Is is stored on the server somewhere? (I hope I have access to it from the shared hosting)

Thanks!


回答1:


If you run delayed job workers daemonized, then you need to restart them to reload the code. Also, keep in mind that each worker loads its own instance of rails.




回答2:


Eventually I figured that out - several workers were running in background, each of them caught a job and had their own cache. I didn't know how to kill them so I changed the table's name for several seconds. That killed them :)

Then I used https://github.com/tobi/delayed_job/wiki/Running-Delayed::Worker-as-a-daemon as worker start, and it works great.



来源:https://stackoverflow.com/questions/1971315/delayed-job-performs-not-up-to-date-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!