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,15 +1,22
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
@@ -37,7 +44,7
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'
@@ -58,13 +65,24
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
You need to be logged in to leave comments. Login now