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"
精彩评论