run and stop rake task from ruby file

邮差的信 提交于 2019-12-11 07:17:48

问题


I already know that running 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!


回答1:


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.




回答2:


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




回答3:


ps afx | grep rake

Then kill the process id

kill -9 "process_id" 


来源:https://stackoverflow.com/questions/6930157/run-and-stop-rake-task-from-ruby-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!