[Why] When use "submit -m job.yaml" to monitor job state, it can't auto stop. Need to enter "Ctrl + c" manually. It's not convenient. So add the function of automatically stopping when "job_state=extract_finished" is received. [Output] connect to ws://localhost:11310/filter {"job_id"=>"z9.105511", "message"=>"", "job_state"=>"submit"} {"job_id"=>"z9.105511", "job_state"=>"boot"} {"job_id"=>"z9.105511", "job_state"=>"download"} {"time"=>"2020-10-22 11:14:55", "mac"=>"xx", "ip"=>"xx", "job_id"=>"z9.105511", "state"=>"running", "testbox"=>"vm-2p8g-3871595"} {"job_state"=>"running", "job_id"=>"z9.105511"} {"job_state"=>"post_run", "job_id"=>"z9.105511"} {"start_time"=>"2020-10-22 03:14:56", "end_time"=>"2020-10-22 03:15:26", "loadavg"=>"1.26 0.38 0.13 2/87 1268", "job_id"=>"z9.105511"} {"job_state"=>"finished", "job_id"=>"z9.105511"} {"job_id"=>"z9.105511", "job_state"=>"complete"} {"time"=>"2020-10-22 11:15:34", "mac"=>"xx", "ip"=>"xx", "job_id"=>"z9.105511", "state"=>"rebooting", "testbox"=>"vm-2p8g-3871595"} {"job_id"=>"z9.105511", "job_state"=>"extract_finished"} connection closed:
Signed-off-by: Wu Zhende wuzhende666@163.com --- sbin/monitor | 6 ++++++ sbin/submit | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/sbin/monitor b/sbin/monitor index c19a6056..def47bf6 100755 --- a/sbin/monitor +++ b/sbin/monitor @@ -14,6 +14,7 @@ opt_action = {'output' => true} opt_job = {} opt_monitor_url = nil opt_timeout = 0 +opt_stop_query = {}
options = OptionParser.new do |opts| opts.banner = 'Usage: monitor [options] <filter>' @@ -49,6 +50,10 @@ options = OptionParser.new do |opts| opts.on('-j', '--job json', 'set job') do |job| opt_job.merge! YAML.load job end + + opts.on('-s', '--stop-query json', 'add query to stop monitor') do |stop_query| + opt_stop_query.merge! YAML.load stop_query + end end
options.parse!(ARGV) @@ -75,5 +80,6 @@ monitor.monitor_url = opt_monitor_url if opt_monitor_url monitor.overrides = opt_set_key_value monitor.action = opt_action monitor.job = opt_job +monitor.stop_query = opt_stop_query
monitor.run(opt_timeout) diff --git a/sbin/submit b/sbin/submit index 8b46db32..c49e1e9a 100755 --- a/sbin/submit +++ b/sbin/submit @@ -16,7 +16,7 @@ opt_output_dir = nil opt_auto_define_files = false opt_monitor = false opt_monitor_query = {} -actions = ['output'] +actions = ['output', 'stop']
options = OptionParser.new do |opts| opts.banner = 'Usage: submit [options] jobs...' @@ -157,6 +157,6 @@ end
if opt_monitor opt_monitor_query.merge!({'job_id' => job_ids[0]}) - cmd = "#{LKP_SRC}/sbin/monitor -f '#{opt_monitor_query.to_json}' -j '#{job_json_list[0]}' -a #{actions.join(',')}" + cmd = "#{LKP_SRC}/sbin/monitor -f '#{opt_monitor_query.to_json}' -j '#{job_json_list[0]}' -a #{actions.join(',')} -s 'job_state: extract_finished'" exec cmd end