Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use faster sidekiq. Schedule is broken

  • Loading branch information...
commit 8bc8e7bc5e6598262a8aba20f064b83cd7c9f0a2 1 parent 3169b90
@randx randx authored
View
7 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'
View
32 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
View
3  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
View
4 app/controllers/projects_controller.rb
@@ -56,7 +56,7 @@ def run
@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 @@ def build
@build = @project.register_build(build_params)
if @build
- Resque.enqueue(Runner, @build.id)
+ Runner.perform_async(@build.id)
head 200
else
head 500
View
4 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
View
2  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
View
2  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"}
View
35 config/initializers/2_resque.rb
@@ -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 = []
View
22 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
View
10 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
View
16 lib/runner.rb
@@ -2,21 +2,25 @@
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
View
31 lib/tasks/resque.rake
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.