简体   繁体   English

Rails延迟的作业生产无法接收班级/作业代码中的更改

[英]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. 我正在运行一堆nginx,passenger,rails,delayed_job gem,它在Ubuntu LTS上从lib / tasks /运行import.rake任务。

If I make a code change on production to import.rake. 如果我在生产上将代码更改为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. 但是,它仍然无法识别我对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 看看是否有任何挥之不去的工作,从所有上面运行delay_job stop命令后,我看到的是

[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? 有任何想法吗?

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. 延迟工作序列化时,它入列代码的实例 ,所以除非你改变你的rake任务调用的代码,而不是rake任务本身调动也无济于事。

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: 因此,您可以执行以下操作来代替MyLogic.delay.do_stuff

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. 然后,只需从您的代码中调用DelayedTask.do_stuff ,就可以以MyLogic.do_stuff的任何方式更改MyLogic.do_stuff (而无需更改方法名称或参数),并且它可以正常工作。

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

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