elado
elado

Reputation: 8760

delayed_job - Performs not up to date code?

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!

Upvotes: 3

Views: 2122

Answers (2)

elado
elado

Reputation: 8760

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.

Upvotes: 2

m33lky
m33lky

Reputation: 7285

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.

Upvotes: 2

Related Questions