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:
- Nothing, if
RAILS_ENV
is already set to production (child processes inherit their parent's environment). - Set the
RAILS_ENV
to production inENV
so that it does get inherited (ENV["RAILS_ENV"] = "production")
Use the
env
command, which allows you to alter the environment a program runs insystem "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 ..."
)
精彩评论