开发者

run and stop rake task from ruby file

开发者 https://www.devze.com 2023-03-25 05:26 出处:网络
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\"

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

精彩评论

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