Permalink
Browse files

change resque to sidekiq

  • Loading branch information...
1 parent 5a0c81c commit cc536f4e3efdafd6773756bcb832548fd0a383bd @halida committed Mar 30, 2013
Showing with 53 additions and 39 deletions.
  1. +4 −2 Gemfile
  2. +21 −16 Gemfile.lock
  3. +1 −1 app/controllers/solutions_controller.rb
  4. +4 −0 app/models/user.rb
  5. +8 −14 app/workers/solution_checker.rb
  6. +0 −3 config/initializers/resque.rb
  7. +15 −3 config/routes.rb
View
@@ -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
@@ -49,20 +49,23 @@ 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)
coffee-script (2.2.0)
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)
@@ -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
@@ -10,4 +10,8 @@ class User < ActiveRecord::Base
has_many :challenges
has_many :solutions
+
+ def admin?
+ self.email == 'linjunhalida@gmail.com'
+ end
end
@@ -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
@@ -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
@@ -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:

0 comments on commit cc536f4

Please sign in to comment.