Description:
[grader] process-wise stop file git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@107 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r24:e6a6003ee7ff - - 1 file changed: 26 inserted, 8 deleted

@@ -1,24 +1,31
1 #!/usr/bin/ruby
1 #!/usr/bin/ruby
2
2
3 - def stop_grader
3 + def stop_grader(id)
4 - File.open(File.dirname(__FILE__) + '/stop','w').close
4 + if id==:all
5 + File.open(File.dirname(__FILE__) + "/stop.all",'w').close
6 + else
7 + File.open(File.dirname(__FILE__) + "/stop.#{id}",'w').close
8 + end
5 end
9 end
6
10
7 def check_stopfile
11 def check_stopfile
8 - FileTest.exist?(File.dirname(__FILE__) + '/stop')
12 + FileTest.exist?(File.dirname(__FILE__) + "/stop.all") or
13 + FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}")
9 end
14 end
10
15
11 def clear_stopfile
16 def clear_stopfile
12 - system("rm " + File.dirname(__FILE__) + '/stop')
17 + if FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}")
18 + system("rm " + File.dirname(__FILE__) + "/stop.#{Process.pid}")
19 + end
13 end
20 end
14
21
15 def config
22 def config
16 Grader::Configuration.get_instance
23 Grader::Configuration.get_instance
17 end
24 end
18
25
19 def log_file_name
26 def log_file_name
20 config.log_dir +
27 config.log_dir +
21 "/#{GRADER_ENV}_#{config.grader_mode}.#{Process.pid}"
28 "/#{GRADER_ENV}_#{config.grader_mode}.#{Process.pid}"
22 end
29 end
23
30
24 def log(str)
31 def log(str)
@@ -28,52 +35,63
28 if config.logging
35 if config.logging
29 fp = File.open(log_file_name,"a")
36 fp = File.open(log_file_name,"a")
30 fp.puts("GRADER: #{Time.new.strftime("%H:%M")} #{str}")
37 fp.puts("GRADER: #{Time.new.strftime("%H:%M")} #{str}")
31 fp.close
38 fp.close
32 end
39 end
33 end
40 end
34
41
35 def display_manual
42 def display_manual
36 puts <<USAGE
43 puts <<USAGE
37 Grader.
44 Grader.
38 using: (1) grader
45 using: (1) grader
39 (2) grader environment [mode]
46 (2) grader environment [mode]
40 - (3) grader stop
47 + (3) grader stop [all|pids-list]
41 (4) grader --help
48 (4) grader --help
42 (1) call grader with environment = 'exam', mode = 'queue'
49 (1) call grader with environment = 'exam', mode = 'queue'
43 (2) possible modes are: 'queue', 'prob', 'test_request'
50 (2) possible modes are: 'queue', 'prob', 'test_request'
44 (3) create stop-file to stop running grader in queue mode
51 (3) create stop-file to stop running grader in queue mode
45 (4) You are here.
52 (4) You are here.
46 USAGE
53 USAGE
47 end
54 end
48
55
49 #########################################
56 #########################################
50 # main program
57 # main program
51 #########################################
58 #########################################
52
59
53 # with --help
60 # with --help
54 if (ARGV.length==1) and (/help/.match(ARGV[0]))
61 if (ARGV.length==1) and (/help/.match(ARGV[0]))
55 display_manual
62 display_manual
56 exit(0)
63 exit(0)
57 end
64 end
58
65
59 # reading environment and options
66 # reading environment and options
60 if (ARGV.length >= 1) and (ARGV[0]=='stop')
67 if (ARGV.length >= 1) and (ARGV[0]=='stop')
61 - stop_grader
68 + if ARGV.length==1
62 - puts "stop file created"
69 + puts "you should specify pid-list or 'all'"
70 + display_manual
71 + elsif (ARGV.length==2) and (ARGV[1]=='all')
72 + stop_grader(:all)
73 + puts "A global stop file ('stop.all') created."
74 + puts "You should remove it manually later."
75 + else
76 + (1..ARGV.length-1).each do |i|
77 + stop_grader(ARGV[i])
78 + end
79 + puts "stop file(s) created"
80 + end
63 exit(0)
81 exit(0)
64 end
82 end
65
83
66 if check_stopfile
84 if check_stopfile
67 - puts "stop file exists"
85 + puts "Stop file exists. Terminated."
68 clear_stopfile
86 clear_stopfile
69 exit(0)
87 exit(0)
70 end
88 end
71
89
72 grader_mode = 'queue'
90 grader_mode = 'queue'
73 if ARGV.length >= 1
91 if ARGV.length >= 1
74 GRADER_ENV = ARGV[0]
92 GRADER_ENV = ARGV[0]
75 if ARGV.length >=2
93 if ARGV.length >=2
76 grader_mode = ARGV[1]
94 grader_mode = ARGV[1]
77 end
95 end
78 else
96 else
79 GRADER_ENV = 'exam'
97 GRADER_ENV = 'exam'
You need to be logged in to leave comments. Login now