Description:
[grader] raise when log directory does not exist
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@108 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
r25:8541b6e657f1 - - 1 file changed: 3 inserted, 0 deleted
@@ -1,122 +1,125 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
3 | def stop_grader(id) |
|
3 | def stop_grader(id) |
|
4 | if id==:all |
|
4 | if id==:all |
|
5 | File.open(File.dirname(__FILE__) + "/stop.all",'w').close |
|
5 | File.open(File.dirname(__FILE__) + "/stop.all",'w').close |
|
6 | else |
|
6 | else |
|
7 | File.open(File.dirname(__FILE__) + "/stop.#{id}",'w').close |
|
7 | File.open(File.dirname(__FILE__) + "/stop.#{id}",'w').close |
|
8 | end |
|
8 | end |
|
9 | end |
|
9 | end |
|
10 |
|
10 | ||
|
11 | def check_stopfile |
|
11 | def check_stopfile |
|
12 | FileTest.exist?(File.dirname(__FILE__) + "/stop.all") or |
|
12 | FileTest.exist?(File.dirname(__FILE__) + "/stop.all") or |
|
13 | FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
13 | FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
14 | end |
|
14 | end |
|
15 |
|
15 | ||
|
16 | def clear_stopfile |
|
16 | def clear_stopfile |
|
17 | if FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
17 | if FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
18 | system("rm " + File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
18 | system("rm " + File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
19 | end |
|
19 | end |
|
20 | end |
|
20 | end |
|
21 |
|
21 | ||
|
22 | def config |
|
22 | def config |
|
23 | Grader::Configuration.get_instance |
|
23 | Grader::Configuration.get_instance |
|
24 | end |
|
24 | end |
|
25 |
|
25 | ||
|
26 | def log_file_name |
|
26 | def log_file_name |
|
|
27 | + if !File.exists?(config.log_dir) | ||
|
|
28 | + raise "Log directory does not exist: #{config.log_dir}" | ||
|
|
29 | + end | ||
|
27 | config.log_dir + |
|
30 | config.log_dir + |
|
28 | "/#{GRADER_ENV}_#{config.grader_mode}.#{Process.pid}" |
|
31 | "/#{GRADER_ENV}_#{config.grader_mode}.#{Process.pid}" |
|
29 | end |
|
32 | end |
|
30 |
|
33 | ||
|
31 | def log(str) |
|
34 | def log(str) |
|
32 | if config.talkative |
|
35 | if config.talkative |
|
33 | puts str |
|
36 | puts str |
|
34 | end |
|
37 | end |
|
35 | if config.logging |
|
38 | if config.logging |
|
36 | fp = File.open(log_file_name,"a") |
|
39 | fp = File.open(log_file_name,"a") |
|
37 | fp.puts("GRADER: #{Time.new.strftime("%H:%M")} #{str}") |
|
40 | fp.puts("GRADER: #{Time.new.strftime("%H:%M")} #{str}") |
|
38 | fp.close |
|
41 | fp.close |
|
39 | end |
|
42 | end |
|
40 | end |
|
43 | end |
|
41 |
|
44 | ||
|
42 | def display_manual |
|
45 | def display_manual |
|
43 | puts <<USAGE |
|
46 | puts <<USAGE |
|
44 | Grader. |
|
47 | Grader. |
|
45 | using: (1) grader |
|
48 | using: (1) grader |
|
46 | (2) grader environment [mode] |
|
49 | (2) grader environment [mode] |
|
47 | (3) grader stop [all|pids-list] |
|
50 | (3) grader stop [all|pids-list] |
|
48 | (4) grader --help |
|
51 | (4) grader --help |
|
49 | (1) call grader with environment = 'exam', mode = 'queue' |
|
52 | (1) call grader with environment = 'exam', mode = 'queue' |
|
50 | (2) possible modes are: 'queue', 'prob', 'test_request' |
|
53 | (2) possible modes are: 'queue', 'prob', 'test_request' |
|
51 | (3) create stop-file to stop running grader in queue mode |
|
54 | (3) create stop-file to stop running grader in queue mode |
|
52 | (4) You are here. |
|
55 | (4) You are here. |
|
53 | USAGE |
|
56 | USAGE |
|
54 | end |
|
57 | end |
|
55 |
|
58 | ||
|
56 | ######################################### |
|
59 | ######################################### |
|
57 | # main program |
|
60 | # main program |
|
58 | ######################################### |
|
61 | ######################################### |
|
59 |
|
62 | ||
|
60 | # with --help |
|
63 | # with --help |
|
61 | if (ARGV.length==1) and (/help/.match(ARGV[0])) |
|
64 | if (ARGV.length==1) and (/help/.match(ARGV[0])) |
|
62 | display_manual |
|
65 | display_manual |
|
63 | exit(0) |
|
66 | exit(0) |
|
64 | end |
|
67 | end |
|
65 |
|
68 | ||
|
66 | # reading environment and options |
|
69 | # reading environment and options |
|
67 | if (ARGV.length >= 1) and (ARGV[0]=='stop') |
|
70 | if (ARGV.length >= 1) and (ARGV[0]=='stop') |
|
68 | if ARGV.length==1 |
|
71 | if ARGV.length==1 |
|
69 | puts "you should specify pid-list or 'all'" |
|
72 | puts "you should specify pid-list or 'all'" |
|
70 | display_manual |
|
73 | display_manual |
|
71 | elsif (ARGV.length==2) and (ARGV[1]=='all') |
|
74 | elsif (ARGV.length==2) and (ARGV[1]=='all') |
|
72 | stop_grader(:all) |
|
75 | stop_grader(:all) |
|
73 | puts "A global stop file ('stop.all') created." |
|
76 | puts "A global stop file ('stop.all') created." |
|
74 | puts "You should remove it manually later." |
|
77 | puts "You should remove it manually later." |
|
75 | else |
|
78 | else |
|
76 | (1..ARGV.length-1).each do |i| |
|
79 | (1..ARGV.length-1).each do |i| |
|
77 | stop_grader(ARGV[i]) |
|
80 | stop_grader(ARGV[i]) |
|
78 | end |
|
81 | end |
|
79 | puts "stop file(s) created" |
|
82 | puts "stop file(s) created" |
|
80 | end |
|
83 | end |
|
81 | exit(0) |
|
84 | exit(0) |
|
82 | end |
|
85 | end |
|
83 |
|
86 | ||
|
84 | if check_stopfile |
|
87 | if check_stopfile |
|
85 | puts "Stop file exists. Terminated." |
|
88 | puts "Stop file exists. Terminated." |
|
86 | clear_stopfile |
|
89 | clear_stopfile |
|
87 | exit(0) |
|
90 | exit(0) |
|
88 | end |
|
91 | end |
|
89 |
|
92 | ||
|
90 | grader_mode = 'queue' |
|
93 | grader_mode = 'queue' |
|
91 | if ARGV.length >= 1 |
|
94 | if ARGV.length >= 1 |
|
92 | GRADER_ENV = ARGV[0] |
|
95 | GRADER_ENV = ARGV[0] |
|
93 | if ARGV.length >=2 |
|
96 | if ARGV.length >=2 |
|
94 | grader_mode = ARGV[1] |
|
97 | grader_mode = ARGV[1] |
|
95 | end |
|
98 | end |
|
96 | else |
|
99 | else |
|
97 | GRADER_ENV = 'exam' |
|
100 | GRADER_ENV = 'exam' |
|
98 | end |
|
101 | end |
|
99 |
|
102 | ||
|
100 | puts "environment: #{GRADER_ENV}" |
|
103 | puts "environment: #{GRADER_ENV}" |
|
101 | require File.join(File.dirname(__FILE__),'config/environment') |
|
104 | require File.join(File.dirname(__FILE__),'config/environment') |
|
102 |
|
105 | ||
|
103 | # add grader_mode to config |
|
106 | # add grader_mode to config |
|
104 | # this is needed because method log needs it. TODO: clean this up |
|
107 | # this is needed because method log needs it. TODO: clean this up |
|
105 | class << config |
|
108 | class << config |
|
106 | attr_accessor :grader_mode |
|
109 | attr_accessor :grader_mode |
|
107 | end |
|
110 | end |
|
108 | config.grader_mode = grader_mode |
|
111 | config.grader_mode = grader_mode |
|
109 |
|
112 | ||
|
110 | # reading rails environment |
|
113 | # reading rails environment |
|
111 | log 'Reading rails environment' |
|
114 | log 'Reading rails environment' |
|
112 |
|
115 | ||
|
113 | RAILS_ENV = config.rails_env |
|
116 | RAILS_ENV = config.rails_env |
|
114 | require RAILS_ROOT + '/config/environment' |
|
117 | require RAILS_ROOT + '/config/environment' |
|
115 |
|
118 | ||
|
116 | # register grader process |
|
119 | # register grader process |
|
117 | if config.report_grader |
|
120 | if config.report_grader |
|
118 | grader_proc = GraderProcess.register(config.grader_hostname, |
|
121 | grader_proc = GraderProcess.register(config.grader_hostname, |
|
119 | Process.pid, |
|
122 | Process.pid, |
|
120 | grader_mode) |
|
123 | grader_mode) |
|
121 | else |
|
124 | else |
|
122 | grader_proc = nil |
|
125 | grader_proc = nil |
You need to be logged in to leave comments.
Login now