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:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r24:e6a6003ee7ff - - 1 file changed: 26 inserted, 8 deleted
@@ -1,15 +1,22 | |||
|
1 | 1 | #!/usr/bin/ruby |
|
2 | 2 | |
|
3 | - def stop_grader | |
|
4 | - File.open(File.dirname(__FILE__) + '/stop','w').close | |
|
3 | + def stop_grader(id) | |
|
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 | 9 | end |
|
6 | 10 | |
|
7 | 11 | def check_stopfile |
|
8 |
- FileTest.exist?(File.dirname(__FILE__) + |
|
|
12 | + FileTest.exist?(File.dirname(__FILE__) + "/stop.all") or | |
|
13 | + FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") | |
|
9 | 14 | end |
|
10 | 15 | |
|
11 | 16 | def clear_stopfile |
|
12 |
- |
|
|
17 | + if FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") | |
|
18 | + system("rm " + File.dirname(__FILE__) + "/stop.#{Process.pid}") | |
|
19 | + end | |
|
13 | 20 | end |
|
14 | 21 | |
|
15 | 22 | def config |
@@ -37,7 +44,7 | |||
|
37 | 44 | Grader. |
|
38 | 45 | using: (1) grader |
|
39 | 46 | (2) grader environment [mode] |
|
40 | - (3) grader stop | |
|
47 | + (3) grader stop [all|pids-list] | |
|
41 | 48 | (4) grader --help |
|
42 | 49 | (1) call grader with environment = 'exam', mode = 'queue' |
|
43 | 50 | (2) possible modes are: 'queue', 'prob', 'test_request' |
@@ -58,13 +65,24 | |||
|
58 | 65 | |
|
59 | 66 | # reading environment and options |
|
60 | 67 | if (ARGV.length >= 1) and (ARGV[0]=='stop') |
|
61 | - stop_grader | |
|
62 | - puts "stop file created" | |
|
68 | + if ARGV.length==1 | |
|
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 | 81 | exit(0) |
|
64 | 82 | end |
|
65 | 83 | |
|
66 | 84 | if check_stopfile |
|
67 |
- puts " |
|
|
85 | + puts "Stop file exists. Terminated." | |
|
68 | 86 | clear_stopfile |
|
69 | 87 | exit(0) |
|
70 | 88 | end |
You need to be logged in to leave comments.
Login now