aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-12-26 21:56:07 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-12-26 21:56:07 +0900
commit0785c946b036afd28b0d189472d4546163f50e2b (patch)
treedc3cb4996afe27c807554e6d86b44dffaeacdfad
parentaa521c6d4105374a5c7837330a98eba58149c675 (diff)
downloadpoe-0785c946b036afd28b0d189472d4546163f50e2b.tar.gz
use sidekiq
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock10
-rw-r--r--app/jobs/execute_job.rb7
-rw-r--r--app/models/compiler.rb17
-rw-r--r--app/models/snippet.rb1
-rw-r--r--config/application.rb2
6 files changed, 39 insertions, 0 deletions
diff --git a/Gemfile b/Gemfile
index 477f700..0f4aec0 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,6 +2,8 @@ source "https://rubygems.org"
gem "rails", ">= 5.0.0.beta1", "< 5.1"
gem "mysql2", ">= 0.3.18", "< 0.5"
+gem "sidekiq"
+gem "sinatra", require: false
gem "sprockets"
gem "uglifier", ">= 1.3.0"
diff --git a/Gemfile.lock b/Gemfile.lock
index 07c3afe..f05b7d5 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -77,6 +77,7 @@ GEM
execjs
coffee-script-source (1.10.0)
concurrent-ruby (1.0.0)
+ connection_pool (2.2.0)
debug_inspector (0.0.2)
em-hiredis (0.3.0)
eventmachine (~> 1.0)
@@ -137,6 +138,13 @@ GEM
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
redis (3.2.2)
+ sidekiq (4.0.1)
+ concurrent-ruby (~> 1.0)
+ connection_pool (~> 2.2, >= 2.2.0)
+ json (~> 1.0)
+ redis (~> 3.2, >= 3.2.1)
+ sinatra (1.0)
+ rack (>= 1.0)
sprockets (3.5.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
@@ -175,6 +183,8 @@ DEPENDENCIES
mysql2 (>= 0.3.18, < 0.5)
puma
rails (>= 5.0.0.beta1, < 5.1)
+ sidekiq
+ sinatra
sprockets
sprockets-es6
turbolinks
diff --git a/app/jobs/execute_job.rb b/app/jobs/execute_job.rb
new file mode 100644
index 0000000..f5dd436
--- /dev/null
+++ b/app/jobs/execute_job.rb
@@ -0,0 +1,7 @@
+class ExecuteJob < ApplicationJob
+ queue_as :default
+
+ def perform(compiler, snippet)
+ compiler.run! snippet
+ end
+end
diff --git a/app/models/compiler.rb b/app/models/compiler.rb
index 0ec28cc..7cf7152 100644
--- a/app/models/compiler.rb
+++ b/app/models/compiler.rb
@@ -1,2 +1,19 @@
class Compiler < ApplicationRecord
+ def _run!(snippet)
+ raise NotImplementedError
+ end
+
+ if Rails.env.development?
+ require "shellwords"
+ def run!(snippet)
+ if self.language == "ruby" && self.version == "!!unsafe!!"
+ out = `ruby -e #{Shellwords.escape(snippet.code)}`
+ Result.create(snippet: snippet, compiler: self, output: out)
+ else
+ _run!(snippet)
+ end
+ end
+ else
+ alias run! _run!
+ end
end
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index 9870f4e..5412492 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -1,3 +1,4 @@
class Snippet < ApplicationRecord
has_many :result
+ has_many :compiler
end
diff --git a/config/application.rb b/config/application.rb
index 2c081c0..4dc52f9 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -21,5 +21,7 @@ module Poe
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
+
+ config.active_job.queue_adapter = :sidekiq
end
end