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,18 +1,25
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
@@ -34,13 +41,13
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
@@ -55,19 +62,30
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
You need to be logged in to leave comments. Login now