Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: halida/easy_oj_web
base: 91aaf540f3
...
head fork: halida/easy_oj_web
compare: 5223113702
  • 3 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
6 Gemfile
@@ -33,8 +33,10 @@ gem 'jbuilder'
gem "truncate_html", "~> 0.5.4"
gem 'will_paginate', '~> 3.0.pre2'
-gem 'resque'
-gem 'rubypython'
+gem 'sidekiq'
+gem 'slim'
+# if you require 'sinatra' you get the DSL extended to Object
+gem 'sinatra', '>= 1.3.0', :require => nil
gem 'haml'
gem 'haml-rails'
View
37 Gemfile.lock
@@ -49,13 +49,15 @@ GEM
arel (3.0.2)
bbenezech-nested_form (0.0.6)
bcrypt-ruby (3.0.1)
- blankslate (2.1.2.4)
bootstrap-sass (2.3.0.1)
sass (~> 3.2)
builder (3.0.4)
cache_digests (0.2.0)
actionpack (>= 3.2)
cancan (1.6.9)
+ celluloid (0.12.4)
+ facter (>= 1.6.12)
+ timers (>= 1.0.0)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -63,6 +65,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.5.0)
+ connection_pool (1.0.0)
devise (1.4.7)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
@@ -71,7 +74,7 @@ GEM
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
- ffi (1.0.11)
+ facter (1.6.18)
formtastic (2.2.1)
actionpack (>= 3.0)
haml (3.1.8)
@@ -113,7 +116,7 @@ GEM
rack-pjax (0.7.0)
nokogiri (~> 1.5)
rack (~> 1.3)
- rack-protection (1.4.0)
+ rack-protection (1.5.0)
rack
rack-ssl (1.3.3)
rack
@@ -144,11 +147,6 @@ GEM
redis (~> 3.0.0)
ref (1.0.2)
remotipart (1.0.5)
- resque (1.23.0)
- multi_json (~> 1.0)
- redis-namespace (~> 1.0)
- sinatra (>= 0.9.2)
- vegas (~> 0.1.2)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
@@ -164,9 +162,6 @@ GEM
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
- rubypython (0.6.3)
- blankslate (>= 2.1.2.3)
- ffi (>= 1.0.7)
sass (3.2.6)
sass-rails (3.2.6)
railties (~> 3.2.0)
@@ -176,20 +171,31 @@ GEM
sextant (0.1.1)
activesupport (>= 3.2)
rails (>= 3.2)
- sinatra (1.3.5)
+ sidekiq (2.9.0)
+ celluloid (~> 0.12.0)
+ connection_pool (~> 1.0)
+ multi_json (~> 1)
+ redis (~> 3)
+ redis-namespace
+ sinatra (1.3.6)
rack (~> 1.4)
rack-protection (~> 1.3)
tilt (~> 1.3, >= 1.3.3)
+ slim (1.3.6)
+ temple (~> 0.5.5)
+ tilt (~> 1.3.3)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
+ temple (0.5.5)
therubyracer (0.11.4)
libv8 (~> 3.11.8.12)
ref
thor (0.17.0)
tilt (1.3.4)
+ timers (1.1.0)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
@@ -202,8 +208,6 @@ GEM
kgio (~> 2.6)
rack
raindrops (~> 0.7)
- vegas (0.1.11)
- rack (>= 1.0.0)
warden (1.0.6)
rack (>= 1.0)
will_paginate (3.0.4)
@@ -225,13 +229,14 @@ DEPENDENCIES
rails (= 3.2.11)
rails_admin!
redcarpet (= 1.17.2)
- resque
rspec
rspec-rails (~> 2.6)
- rubypython
sass-rails (~> 3.2.3)
settingslogic
sextant
+ sidekiq
+ sinatra (>= 1.3.0)
+ slim
therubyracer
truncate_html (~> 0.5.4)
uglifier (>= 1.0.3)
View
2  app/controllers/solutions_controller.rb
@@ -75,7 +75,7 @@ def create
respond_to do |format|
if @solution.save
- Resque.enqueue SolutionChecker, @solution.id
+ SolutionChecker.new.perform(@solution.id)
format.html { redirect_to solutions_path, notice: 'Solution was successfully created.' }
format.json { render json: @solution, status: :created, location: @solution }
else
View
4 app/models/user.rb
@@ -10,4 +10,8 @@ class User < ActiveRecord::Base
has_many :challenges
has_many :solutions
+
+ def admin?
+ self.email == 'linjunhalida@gmail.com'
+ end
end
View
31 app/workers/solution_checker.rb
@@ -1,10 +1,9 @@
-require 'rubypython'
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
@@ -12,25 +11,27 @@ def self.perform(id)
solution.update_attributes(
result: result.to_yaml,
- status: 'Accepted',
+ status: result['result'],
)
end
- def self.create_temp_file solution
+ def create_temp_file solution
+ data = {
+ code: solution.code,
+ language: solution.language,
+ input: solution.problem.input,
+ output: solution.problem.output,
+ }
+
file = Tempfile.new 'solution'
- file.write(solution.code)
+ file.write(data.to_json)
file.path
end
- def self.sandbox_run filename
- return {result: 'ok'}
- s = self.sandbox.Sandbox(['python', filename])
- s.run()
- result = s.probe().rubify
- end
-
- def sandbox
- @sandbox ||= RubyPython.import("sandbox")
+ def sandbox_run filename
+ return {'result' => 'Accepted'}
+ result = `#{Rails.root}/../sandbox/sandbox #{filename}`
+ JSON.load result
end
end
View
3  config/initializers/resque.rb
@@ -1,3 +0,0 @@
-require 'resque'
-Resque.redis = Redis.new host: Settings.redis.host, port: Settings.redis.port
-Resque.redis.namespace = "resque:env_#{Rails.env}:easy_oj_web"
View
18 config/routes.rb
@@ -1,4 +1,16 @@
-require 'resque/server'
+require 'sidekiq/web'
+
+def route_can? p, o
+ lambda do |req|
+ (u = req.env['warden'].user) and u.present? and Ability.new(u).can?(p, o)
+ end
+end
+
+def admin?
+ lambda do |req|
+ u = req.env['warden'].user and u.admin?
+ end
+end
EasyOjWeb::Application.routes.draw do
@@ -18,8 +30,8 @@
devise_for :users
- namespace :sudo do
- mount Resque::Server.new, at: "/resque"
+ namespace :sudo, constraints: admin? do
+ mount Sidekiq::Web => '/sidekiq'
end
# The priority is based upon order of creation:

No commit comments for this range

Something went wrong with that request. Please try again.