jim
jim

Reputation: 1137

Rails Delayed Job production not picking up change in class/job code

I am running a stack of nginx, passenger, rails, delayed_job gem which is running an import.rake task from lib/tasks/ on Ubuntu LTS.

If I make a code change on production to import.rake.

I do a

RAILS_ENV=production script/delayed_job stop
touch tmp/restart.txt
ps aux | egrep '(PID|nginx)'
sudo kill -HUP [PID]
RAILS_ENV=production script/delayed_job start

However, it still does not recognize my change of import.rake. I'm at a loss of what to do. Maybe there is something i'm not thinking of?

I've ran

ps -ef | grep delayed_job

to see if there are any lingering jobs and after running the delayed_job stop command from above all i see is

[server_name] 9426  6168  0 18:46 pts/0    00:00:00 grep --color=auto delayed_job

which shouldn't be an issue. I've also tried just rebooting the server which didn't help.

Any ideas?

Upvotes: 1

Views: 1005

Answers (1)

Spajus
Spajus

Reputation: 7406

Delayed job serializes the instance of your code when it enqueues it, so redeployment won't help unless you change the code that is invoked by your rake task, rather than the rake task itself.

To solve this, decouple the code you change between redeployments from the code that is invoked via delayed job. So, instead of MyLogic.delay.do_stuff, you could do this:

class DelayedTask
  def self.do_stuff
    self.new.delay.execute
  end

  private 

  def execute
    MyLogic.do_stuff
  end
end

Then just call DelayedTask.do_stuff from your code, and you can change MyLogic.do_stuff in any way you want (without changing the method name or params), ant it will work.

Upvotes: 2

Related Questions