Skip to content

Commit

Permalink
Fix null pointer exception of assignment processing status
Browse files Browse the repository at this point in the history
  • Loading branch information
sibinhho99 committed Dec 19, 2023
1 parent 549a184 commit 22b2954
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions lib/submissions_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,25 @@ def self.fork_Java_process(compare_dir, assignment, isMapEnabled, used_fingerpri
%Q{#{assignment.id} #{compare_dir} #{assignment.language.downcase} } +
%Q{#{assignment.min_match_length} #{assignment.ngram_size} } +
%Q{#{host} #{database} #{username} #{password} #{isMapEnabled} #{used_fingerprints}}

process = assignment.submission_similarity_process

if process.nil? # Create process
SubmissionSimilarityProcess.create do |p|
p.assignment_id = assignment.id
p.status = SubmissionSimilarityProcess::STATUS_RUNNING
end

# reload assignment and process
assignment = Assignment.find(assignment.id)
process = assignment.submission_similarity_process
else
process.status = SubmissionSimilarityProcess::STATUS_RUNNING
process.save
end

return if Rails.env.test? # Don't launch Java program in test environment

# Fork to run java program in background
ruby_pid = Process.fork do
java_log = ""
Expand All @@ -214,9 +233,7 @@ def self.fork_Java_process(compare_dir, assignment, isMapEnabled, used_fingerpri
upload_log << assignment.upload_log if assignment.upload_log
upload_log << java_log.truncate(MAX_DATA_CHAR_SIZE, separator: ' ', omission: DATA_TRUNCATE_MSG)
assignment.upload_log = upload_log.join("\n")

# Update status
process = assignment.submission_similarity_process

if java_status.exitstatus == 0
process.status = SubmissionSimilarityProcess::STATUS_COMPLETED
else
Expand All @@ -232,20 +249,7 @@ def self.fork_Java_process(compare_dir, assignment, isMapEnabled, used_fingerpri
end
end

# Create process with pid
process = assignment.submission_similarity_process
if process.nil?
SubmissionSimilarityProcess.create do |p|
p.assignment_id = assignment.id
p.pid = ruby_pid
p.status = SubmissionSimilarityProcess::STATUS_RUNNING
end
else
process.pid = ruby_pid
process.status = SubmissionSimilarityProcess::STATUS_RUNNING
process.save
end

process.pid = ruby_pid
Process.detach(ruby_pid) # Parent will not wait
end

Expand Down

0 comments on commit 22b2954

Please sign in to comment.