开发者

ruby system call to restart delayed job is failing

My delayed job processes seem to randomly disappear, I am working on a longer term fix for this, but in the mean time, I think simply restarting them when I need them should do the trick. Since I have a ruby batch job that needs delayed job to process when its running, I thought I would just restart the delayed job processes at the start using:

system_call_result = system( "RAILS_ENV=production ruby script/delayed_job -n7 restart" )

This doesnt work, the call returns false and it does nothing. So I also tried:

system_call_result1 = system( "RAILS_ENV=production ruby script/delayed_job stop" )
system_call_result2 = system( "RAILS_ENV=production ruby script/delayed_job -n7 start" )

Again this doesn't work.

I haven't done many system calls so im sure its somethi开发者_Go百科ng basic.

I did: >> foo = "system("ls -la")

and it lists files in the base rails directory, so it seems like im in the right spot.


Prefixing a command with environment variables isn't a proper command (I think it's a bashism, but I could be wrong). You could do a few different things:

  1. Nothing, if RAILS_ENV is already set to production (child processes inherit their parent's environment).
  2. Set the RAILS_ENV to production in ENV so that it does get inherited (ENV["RAILS_ENV"] = "production")
  3. Use the env command, which allows you to alter the environment a program runs in

     system "env RAILS_ENV=production ruby ..."
    

    (or you could wrap your command in bash so that the environment-prefix works... system 'bash -c "RAILS_ENV=production ruby ...")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜