summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-01-14 17:02:23 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-01-14 17:02:23 +0200
commit8bc8e7bc5e6598262a8aba20f064b83cd7c9f0a2 (patch)
treed5d6681bfafd71596a75cf5205abdf31424f0ca0
parent3169b900cc5005c88c7e6bdce0bdd36561978c01 (diff)
downloadgitlab-ci-8bc8e7bc5e6598262a8aba20f064b83cd7c9f0a2.tar.gz
Use faster sidekiq. Schedule is broken
-rw-r--r--Gemfile7
-rw-r--r--Gemfile.lock32
-rw-r--r--Procfile3
-rw-r--r--app/controllers/projects_controller.rb4
-rw-r--r--app/models/user.rb4
-rw-r--r--app/views/layouts/application.html.haml2
-rw-r--r--app/views/resques/show.html.haml2
-rw-r--r--config/initializers/2_resque.rb35
-rw-r--r--config/initializers/2_sidekiq.rb22
-rw-r--r--config/routes.rb10
-rw-r--r--lib/runner.rb16
-rw-r--r--lib/tasks/resque.rake31
12 files changed, 70 insertions, 98 deletions
diff --git a/Gemfile b/Gemfile
index bfad577..efcd58a 100644
--- a/Gemfile
+++ b/Gemfile
@@ -26,9 +26,10 @@ gem "unicorn", "~> 4.4.0"
# Haml
gem 'haml-rails'
-# Jobs
-gem 'resque'
-gem 'resque-scheduler', :require => 'resque_scheduler'
+# Background jobs
+gem 'slim'
+gem 'sinatra', :require => nil
+gem 'sidekiq', '2.6.4'
# Format dates
gem 'stamp'
diff --git a/Gemfile.lock b/Gemfile.lock
index d414a2f..2f6643b 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -41,6 +41,9 @@ GEM
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
+ celluloid (0.12.4)
+ facter (>= 1.6.12)
+ timers (>= 1.0.0)
childprocess (0.3.5)
ffi (~> 1.0, >= 1.0.6)
coderay (1.0.8)
@@ -51,6 +54,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.4.0)
+ connection_pool (1.0.0)
daemons (1.1.9)
devise (2.1.2)
bcrypt-ruby (~> 3.0)
@@ -62,6 +66,7 @@ GEM
eventmachine (1.0.0)
execjs (1.4.0)
multi_json (~> 1.0)
+ facter (1.6.17)
factory_girl (4.1.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.1.0)
@@ -152,15 +157,6 @@ GEM
redis (3.0.2)
redis-namespace (1.2.1)
redis (~> 3.0.0)
- resque (1.23.0)
- multi_json (~> 1.0)
- redis-namespace (~> 1.0)
- sinatra (>= 0.9.2)
- vegas (~> 0.1.2)
- resque-scheduler (2.0.0)
- redis (>= 2.0.1)
- resque (>= 1.20.0)
- rufus-scheduler
rspec (2.11.0)
rspec-core (~> 2.11.0)
rspec-expectations (~> 2.11.0)
@@ -175,8 +171,6 @@ GEM
railties (>= 3.0)
rspec (~> 2.11.0)
rubyzip (0.9.9)
- rufus-scheduler (2.0.17)
- tzinfo (>= 0.3.23)
sass (3.2.1)
sass-rails (3.2.5)
railties (~> 3.2.0)
@@ -190,10 +184,19 @@ GEM
settingslogic (2.0.8)
shoulda-matchers (1.3.0)
activesupport (>= 3.0.0)
+ sidekiq (2.6.4)
+ celluloid (~> 0.12.0)
+ connection_pool (~> 1.0)
+ multi_json (~> 1)
+ redis (~> 3)
+ redis-namespace
sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
+ slim (1.3.6)
+ temple (~> 0.5.5)
+ tilt (~> 1.3.3)
slop (3.3.3)
sprockets (2.1.3)
hike (~> 1.2)
@@ -201,6 +204,7 @@ GEM
tilt (~> 1.1, != 1.3.0)
stamp (0.3.0)
state_machine (1.1.2)
+ temple (0.5.5)
therubyracer (0.10.2)
libv8 (~> 3.3.10)
thin (1.5.0)
@@ -209,6 +213,7 @@ GEM
rack (>= 1.0.0)
thor (0.16.0)
tilt (1.3.3)
+ timers (1.0.2)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
@@ -254,12 +259,13 @@ DEPENDENCIES
rake
rb-fsevent
rb-inotify
- resque
- resque-scheduler
rspec-rails
sass-rails (~> 3.2.3)
settingslogic
shoulda-matchers
+ sidekiq (= 2.6.4)
+ sinatra
+ slim
stamp
state_machine
therubyracer
diff --git a/Procfile b/Procfile
index 5b0b8b7..2d8146d 100644
--- a/Procfile
+++ b/Procfile
@@ -1,3 +1,2 @@
web: bundle exec rails s -p $PORT
-worker: bundle exec rake environment resque:work QUEUE=runner,scheduler_task VVERBOSE=1
-schedule: bundle exec rake environment resque:scheduler VVERBOSE=1 RAILS_ENV=development
+worker: bundle exec sidekiq -q runner,default
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 31e14ab..1f97e01 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -56,7 +56,7 @@ class ProjectsController < ApplicationController
@build = @project.register_build(ref: params[:ref])
if @build and @build.id
- Resque.enqueue(Runner, @build.id)
+ Runner.perform_async(@build.id)
redirect_to project_build_path(@project, @build)
else
redirect_to project_path(@project), notice: 'Branch is not defined for this project'
@@ -77,7 +77,7 @@ class ProjectsController < ApplicationController
@build = @project.register_build(build_params)
if @build
- Resque.enqueue(Runner, @build.id)
+ Runner.perform_async(@build.id)
head 200
else
head 500
diff --git a/app/models/user.rb b/app/models/user.rb
index 026a4bb..81f9d45 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -6,6 +6,10 @@ class User < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
+
+ def admin?
+ true
+ end
end
# == Schema Information
diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml
index 1383178..9d820b4 100644
--- a/app/views/layouts/application.html.haml
+++ b/app/views/layouts/application.html.haml
@@ -19,7 +19,7 @@
%li
= link_to 'Users', users_path
%li
- = link_to 'Resque', resque_path
+ = link_to 'Background Jobs', resque_path
%li
= link_to edit_user_path(current_user) do
%i.icon-user.icon-white
diff --git a/app/views/resques/show.html.haml b/app/views/resques/show.html.haml
index 02e35fa..4db6312 100644
--- a/app/views/resques/show.html.haml
+++ b/app/views/resques/show.html.haml
@@ -1,4 +1,4 @@
-%h3.page_title Resque
+%h3.page_title Background Jobs
%br
.bordered
%iframe{src: ext_resque_url, width: '100%', height: 600, style: "border: none"}
diff --git a/config/initializers/2_resque.rb b/config/initializers/2_resque.rb
deleted file mode 100644
index de13b7c..0000000
--- a/config/initializers/2_resque.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require Rails.root.join('lib', 'runner')
-require 'scheduler_job'
-
-# Custom Redis configuration
-config_file = Rails.root.join('config', 'resque.yml')
-
-if File.exists?(config_file)
- resque_config = YAML.load_file(config_file)
- Resque.redis = resque_config[Rails.env]
-end
-
-Resque.redis.namespace = 'resque:gitlab_ci'
-
-# Queues
-Resque.watch_queue(Runner.instance_variable_get("@queue"))
-
-# Authentication
-require 'resque/server'
-class Authentication
- def initialize(app)
- @app = app
- end
-
- def call(env)
- account = env['warden'].authenticate!(:database_authenticatable, :rememberable, scope: :user)
- raise "Access denied" if !account#.admin?
- @app.call(env)
- end
-end
-
-Resque::Server.use Authentication
-
-# Mailer
-# For future email notifications
-#Resque::Mailer.excluded_environments = []
diff --git a/config/initializers/2_sidekiq.rb b/config/initializers/2_sidekiq.rb
new file mode 100644
index 0000000..c2d380f
--- /dev/null
+++ b/config/initializers/2_sidekiq.rb
@@ -0,0 +1,22 @@
+# Custom Redis configuration
+config_file = Rails.root.join('config', 'resque.yml')
+
+resque_url = if File.exists?(config_file)
+ YAML.load_file(config_file)[Rails.env]
+ else
+ "localhost:6379"
+ end
+
+Sidekiq.configure_server do |config|
+ config.redis = {
+ url: "redis://#{resque_url}",
+ namespace: 'resque:gitlab_ci'
+ }
+end
+
+Sidekiq.configure_client do |config|
+ config.redis = {
+ url: "redis://#{resque_url}",
+ namespace: 'resque:gitlab_ci'
+ }
+end
diff --git a/config/routes.rb b/config/routes.rb
index be71698..848f8ee 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,9 +1,11 @@
+require 'sidekiq/web'
+
GitlabCi::Application.routes.draw do
# Optionally, enable Resque here
- require 'resque/server'
- require 'resque_scheduler'
- require 'resque_scheduler/server'
- mount Resque::Server => '/ext/resque', as: 'ext_resque'
+ constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? }
+ constraints constraint do
+ mount Sidekiq::Web, at: "/ext/sidekiq", as: :ext_resque
+ end
resources :projects do
member do
diff --git a/lib/runner.rb b/lib/runner.rb
index b546250..530ee3c 100644
--- a/lib/runner.rb
+++ b/lib/runner.rb
@@ -2,21 +2,25 @@ require 'open3'
require 'timeout'
class Runner
+ include Sidekiq::Worker
+
TIMEOUT = 1800
attr_accessor :project, :build, :output
- @queue = :runner
- def self.perform(build_id)
- new(Build.find(build_id)).run
+ sidekiq_options queue: :runner
+
+ def perform(build_id)
+ @build = Build.find(build_id)
+ @project = @build.project
+
+ run
end
- def initialize(build)
+ def initialize
@logger = Logger.new(STDOUT)
@logger.level = Logger::INFO
- @build = build
- @project = build.project
@output = ''
end
diff --git a/lib/tasks/resque.rake b/lib/tasks/resque.rake
deleted file mode 100644
index 2e26680..0000000
--- a/lib/tasks/resque.rake
+++ /dev/null
@@ -1,31 +0,0 @@
-require 'resque/tasks'
-require 'resque_scheduler/tasks'
-
-namespace :resque do
- task :setup => :environment do
- require 'resque'
- require 'resque_scheduler'
-
- # you probably already have this somewhere
- #Resque.redis = 'localhost:6379'
-
- # If you want to be able to dynamically change the schedule,
- # uncomment this line. A dynamic schedule can be updated via the
- # Resque::Scheduler.set_schedule (and remove_schedule) methods.
- # When dynamic is set to true, the scheduler process looks for
- # schedule changes and applies them on the fly.
- # Note: This feature is only available in >=2.0.0.
- Resque::Scheduler.dynamic = true
-
- # The schedule doesn't need to be stored in a YAML, it just needs to
- # be a hash. YAML is usually the easiest.
- #Resque.schedule = YAML.load_file('your_resque_schedule.yml')
-
- # If your schedule already has +queue+ set for each job, you don't
- # need to require your jobs. This can be an advantage since it's
- # less code that resque-scheduler needs to know about. But in a small
- # project, it's usually easier to just include you job classes here.
- # So, something like this:
- #require 'jobs'
- end
-end