开发者

run and stop rake task from ruby file

I already know that runn开发者_JAVA百科ing a rake task from .rb file can be done by running:

system "/usr/bin/rake #{task} #{args.join(' ')} > #{Rails.root}/log/rake.log"

But how to stop a currently running rake task from ruby file?

Thanks!


Perhaps you could do a

ps_aux = system "ps aux | grep #rake_task_name"

then, parse the pid. then, issue a kill command

system "kill #pid"

I haven't tried this yet though.


From within the script, you could run the commands suggested by pat (parsing for the pid) in backticks, system or the %x{} wrapper.


ps afx | grep rake

Then kill the process id

kill -9 "process_id" 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜