-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
53 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,37 @@ | ||
require 'tempfile' | ||
|
||
class SolutionChecker | ||
@queue = self.name.underscore | ||
include Sidekiq::Worker | ||
|
||
def self.perform(id) | ||
def perform(id) | ||
solution = Solution.find(id) | ||
|
||
filename = self.create_temp_file solution | ||
result = self.sandbox_run(filename) | ||
|
||
solution.update_attributes( | ||
result: result.to_yaml, | ||
status: result.status, | ||
status: result['result'], | ||
) | ||
end | ||
|
||
def self.create_temp_file solution | ||
def create_temp_file solution | ||
data = { | ||
code: solution.code, | ||
language: solution.language, | ||
input: solution.question.input, | ||
output: solution.question.output, | ||
input: solution.problem.input, | ||
output: solution.problem.output, | ||
} | ||
|
||
file = Tempfile.new 'solution' | ||
file.write(data.to_json) | ||
file.path | ||
end | ||
|
||
def self.sandbox_run filename | ||
def sandbox_run filename | ||
return {'result' => 'Accepted'} | ||
result = `#{Rails.root}/../sandbox/sandbox #{filename}` | ||
JSON.load result | ||
end | ||
|
||
def sandbox | ||
@sandbox ||= begin | ||
RubyPython.start | ||
RubyPython.import("sandbox") | ||
end | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters