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,24 +1,31 | |||
|
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 |
|
16 | 23 | Grader::Configuration.get_instance |
|
17 | 24 | end |
|
18 | 25 | |
|
19 | 26 | def log_file_name |
|
20 | 27 | config.log_dir + |
|
21 | 28 | "/#{GRADER_ENV}_#{config.grader_mode}.#{Process.pid}" |
|
22 | 29 | end |
|
23 | 30 | |
|
24 | 31 | def log(str) |
@@ -28,52 +35,63 | |||
|
28 | 35 | if config.logging |
|
29 | 36 | fp = File.open(log_file_name,"a") |
|
30 | 37 | fp.puts("GRADER: #{Time.new.strftime("%H:%M")} #{str}") |
|
31 | 38 | fp.close |
|
32 | 39 | end |
|
33 | 40 | end |
|
34 | 41 | |
|
35 | 42 | def display_manual |
|
36 | 43 | puts <<USAGE |
|
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' |
|
44 | 51 | (3) create stop-file to stop running grader in queue mode |
|
45 | 52 | (4) You are here. |
|
46 | 53 | USAGE |
|
47 | 54 | end |
|
48 | 55 | |
|
49 | 56 | ######################################### |
|
50 | 57 | # main program |
|
51 | 58 | ######################################### |
|
52 | 59 | |
|
53 | 60 | # with --help |
|
54 | 61 | if (ARGV.length==1) and (/help/.match(ARGV[0])) |
|
55 | 62 | display_manual |
|
56 | 63 | exit(0) |
|
57 | 64 | end |
|
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 |
|
71 | 89 | |
|
72 | 90 | grader_mode = 'queue' |
|
73 | 91 | if ARGV.length >= 1 |
|
74 | 92 | GRADER_ENV = ARGV[0] |
|
75 | 93 | if ARGV.length >=2 |
|
76 | 94 | grader_mode = ARGV[1] |
|
77 | 95 | end |
|
78 | 96 | else |
|
79 | 97 | GRADER_ENV = 'exam' |
You need to be logged in to leave comments.
Login now