1

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?

4

1 回答 1

2

延迟作业在将代码实例排入队列时将其序列化,因此除非您更改 rake 任务调用代码,而不是 rake 任务本身,否则重新部署将无济于事。

要解决此问题,请将您在重新部署之间更改的代码与通过延迟作业调用的代码分离。因此,MyLogic.delay.do_stuff您可以这样做:

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

  private 

  def execute
    MyLogic.do_stuff
  end
end

然后只需DelayedTask.do_stuff从您的代码中调用,您可以MyLogic.do_stuff以任何您想要的方式进行更改(无需更改方法名称或参数),它会起作用。

于 2013-05-20T19:04:33.600 回答