Description:
added default grading mode, changed log message in grader
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@393 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
r187:a677937ad928 - - 2 files changed: 7 inserted, 5 deleted
@@ -1,58 +1,60 | |||
|
1 | 1 | class GraderMessage < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | belongs_to :taken_grader_process, :class_name => :grader_process |
|
4 | 4 | |
|
5 | 5 | GRADE_SUBMISSION = 1 |
|
6 | 6 | GRADE_TEST_REQUEST = 2 |
|
7 | 7 | STOP = 3 |
|
8 | 8 | |
|
9 | 9 | RECIPIENT_ANY = -1 |
|
10 | 10 | |
|
11 | 11 | def self.create_message(recipient, command, options=nil, target_id=nil) |
|
12 | 12 | recipient_id = recipient |
|
13 | 13 | if recipient == :any |
|
14 | 14 | recipient_id = GraderMessage::RECIPIENT_ANY |
|
15 | 15 | end |
|
16 | 16 | |
|
17 | 17 | GraderMessage.create(:grader_process_id => recipient_id, |
|
18 | 18 | :command => command, |
|
19 | 19 | :options => options, |
|
20 | 20 | :target_id => target_id, |
|
21 | 21 | :taken => false) |
|
22 | 22 | end |
|
23 | 23 | |
|
24 |
- def self.create_grade_submission( |
|
|
24 | + def self.create_grade_submission(submission, | |
|
25 | + grading_environment="grading") | |
|
25 | 26 | GraderMessage.create_message(:any, |
|
26 | 27 | GraderMessage::GRADE_SUBMISSION, |
|
27 |
- m |
|
|
28 | + grading_environment, | |
|
28 | 29 | submission.id) |
|
29 | 30 | end |
|
30 | 31 | |
|
31 |
- def self.create_grade_test_request( |
|
|
32 | + def self.create_grade_test_request(test_request, | |
|
33 | + grading_environment="grading") | |
|
32 | 34 | GraderMessage.create_message(:any, |
|
33 | 35 | GraderMessage::GRADE_TEST_REQUEST, |
|
34 |
- m |
|
|
36 | + grading_environment, | |
|
35 | 37 | test_request.id) |
|
36 | 38 | end |
|
37 | 39 | |
|
38 | 40 | def self.create_stop(grader_process_id) |
|
39 | 41 | GraderMessage.create_message(grader_process_id, |
|
40 | 42 | GraderMessage::STOP) |
|
41 | 43 | end |
|
42 | 44 | |
|
43 | 45 | def self.get_message_for(recipient_id, accepting_commands=:all) |
|
44 | 46 | command_conditions = |
|
45 | 47 | GraderMessage.build_command_conditions(accepting_commands) |
|
46 | 48 | recp_conditions= "((`grader_process_id` = #{recipient_id.to_i})" + |
|
47 | 49 | " OR (`grader_process_id` = #{GraderMessage::RECIPIENT_ANY}))" |
|
48 | 50 | |
|
49 | 51 | message = nil # need this to bind message in do-block for transaction |
|
50 | 52 | begin |
|
51 | 53 | GraderMessage.transaction do |
|
52 | 54 | message = GraderMessage.find(:first, |
|
53 | 55 | :order => "created_at", |
|
54 | 56 | :conditions => |
|
55 | 57 | "(`taken` = 0)" + |
|
56 | 58 | " AND (#{recp_conditions})" + |
|
57 | 59 | " AND (#{command_conditions})", |
|
58 | 60 | :lock => true) |
@@ -7,49 +7,49 | |||
|
7 | 7 | File.open(File.dirname(__FILE__) + "/stop.#{id}",'w').close |
|
8 | 8 | end |
|
9 | 9 | end |
|
10 | 10 | |
|
11 | 11 | def check_stopfile |
|
12 | 12 | FileTest.exist?(File.dirname(__FILE__) + "/stop.all") or |
|
13 | 13 | FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
14 | 14 | end |
|
15 | 15 | |
|
16 | 16 | def clear_stopfile |
|
17 | 17 | if FileTest.exist?(File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
18 | 18 | system("rm " + File.dirname(__FILE__) + "/stop.#{Process.pid}") |
|
19 | 19 | end |
|
20 | 20 | end |
|
21 | 21 | |
|
22 | 22 | def config |
|
23 | 23 | Grader::Configuration.get_instance |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | def log_file_name |
|
27 | 27 | if !File.exists?(config.log_dir) |
|
28 | 28 | raise "Log directory does not exist: #{config.log_dir}" |
|
29 | 29 | end |
|
30 | 30 | config.log_dir + |
|
31 |
- "/#{GRADER_ENV} |
|
|
31 | + "/#{GRADER_ENV}.#{Process.pid}" | |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def log(str) |
|
35 | 35 | if config.talkative |
|
36 | 36 | puts str |
|
37 | 37 | end |
|
38 | 38 | if config.logging |
|
39 | 39 | fp = File.open(log_file_name,"a") |
|
40 | 40 | fp.puts("GRADER: #{Time.new.strftime("%H:%M")} #{str}") |
|
41 | 41 | fp.close |
|
42 | 42 | end |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | def display_manual |
|
46 | 46 | puts <<USAGE |
|
47 | 47 | Grader. |
|
48 | 48 | using: (1) grader |
|
49 | 49 | (2) grader environment [mode] |
|
50 | 50 | (3) grader stop [all|pids-list] |
|
51 | 51 | (4) grader --help |
|
52 | 52 | (1) call grader with environment = 'exam', mode = 'queue' |
|
53 | 53 | (2) possible modes are: 'queue', 'prob', 'test_request' |
|
54 | 54 | (3) create stop-file to stop running grader in queue mode |
|
55 | 55 | (4) You are here. |
You need to be logged in to leave comments.
Login now