Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Trying out Sidekiq.

  • Loading branch information...
commit 2414a61026ddc0e5b6153770b1d3b394b90a487d 1 parent 061ddb5
Thomas Mayfield authored November 04, 2012
7  Gemfile
@@ -7,9 +7,10 @@ gem 'hpricot'
7 7
 gem 'goodreads', :git => 'git://github.com/thegreatape/goodreads.git', :ref => '762a1487556f'
8 8
 gem 'oauth'
9 9
 gem 'dynamic_form'
10  
-gem 'resque', "~> 1.22.0"
11  
-gem 'resque-scheduler'
12  
-gem 'hirefire'
  10
+gem 'sidekiq'
  11
+gem 'sinatra', require: false
  12
+gem 'slim'
  13
+gem 'autoscaler'
13 14
 gem 'will_paginate'
14 15
 gem 'thin'
15 16
 gem 'newrelic_rpm'
58  Gemfile.lock
@@ -42,6 +42,9 @@ GEM
42 42
     addressable (2.3.2)
43 43
     ansi (1.4.3)
44 44
     arel (3.0.2)
  45
+    autoscaler (0.0.2)
  46
+      heroku-api
  47
+      sidekiq (~> 2.2)
45 48
     builder (3.0.0)
46 49
     capistrano (2.12.0)
47 50
       highline
@@ -59,6 +62,9 @@ GEM
59 62
     capybara-webkit (0.12.1)
60 63
       capybara (>= 1.0.0, < 1.2)
61 64
       json
  65
+    celluloid (0.12.3)
  66
+      facter (>= 1.6.12)
  67
+      timers (>= 1.0.0)
62 68
     childprocess (0.3.5)
63 69
       ffi (~> 1.0, >= 1.0.6)
64 70
     coffee-rails (3.2.2)
@@ -68,6 +74,7 @@ GEM
68 74
       coffee-script-source
69 75
       execjs
70 76
     coffee-script-source (1.3.3)
  77
+    connection_pool (0.9.2)
71 78
     daemons (1.1.9)
72 79
     database_cleaner (0.8.0)
73 80
     dynamic_form (1.1.4)
@@ -76,29 +83,20 @@ GEM
76 83
     excon (0.16.7)
77 84
     execjs (1.4.0)
78 85
       multi_json (~> 1.0)
  86
+    facter (1.6.14)
79 87
     factory_girl (2.3.2)
80 88
       activesupport
81 89
     factory_girl_rails (1.4.0)
82 90
       factory_girl (~> 2.3.0)
83 91
       railties (>= 3.0.0)
84 92
     fakeweb (1.3.0)
85  
-    fattr (2.2.1)
86 93
     ffi (1.1.5)
87 94
     haml (3.1.6)
88 95
     hashie (1.0.0)
89  
-    heroku (2.33.0)
90  
-      heroku-api (~> 0.3.5)
91  
-      launchy (>= 0.3.2)
92  
-      netrc (~> 0.7.7)
93  
-      rest-client (~> 1.6.1)
94  
-      rubyzip
95 96
     heroku-api (0.3.6)
96 97
       excon (~> 0.16.7)
97 98
     highline (1.6.13)
98 99
     hike (1.2.1)
99  
-    hirefire (0.1.4)
100  
-      heroku (>= 1.4)
101  
-      rush (~> 0.6.7)
102 100
     hpricot (0.8.6)
103 101
     i18n (0.6.0)
104 102
     journey (1.0.4)
@@ -106,8 +104,6 @@ GEM
106 104
       railties (>= 3.2.0, < 5.0)
107 105
       thor (~> 0.14)
108 106
     json (1.7.4)
109  
-    launchy (2.1.2)
110  
-      addressable (~> 2.3)
111 107
     libwebsocket (0.1.5)
112 108
       addressable
113 109
     mail (2.4.4)
@@ -127,7 +123,6 @@ GEM
127 123
     net-ssh (2.5.2)
128 124
     net-ssh-gateway (1.1.0)
129 125
       net-ssh (>= 1.99.1)
130  
-    netrc (0.7.7)
131 126
     newrelic_rpm (3.5.0.1)
132 127
     nokogiri (1.5.5)
133 128
     oauth (0.4.6)
@@ -160,25 +155,12 @@ GEM
160 155
     rake (0.9.2.2)
161 156
     rdoc (3.12)
162 157
       json (~> 1.4)
163  
-    redis (3.0.1)
  158
+    redis (3.0.2)
164 159
     redis-namespace (1.2.1)
165 160
       redis (~> 3.0.0)
166  
-    resque (1.22.0)
167  
-      multi_json (~> 1.0)
168  
-      redis-namespace (~> 1.0)
169  
-      sinatra (>= 0.9.2)
170  
-      vegas (~> 0.1.2)
171  
-    resque-scheduler (2.0.0)
172  
-      redis (>= 2.0.1)
173  
-      resque (>= 1.20.0)
174  
-      rufus-scheduler
175 161
     rest-client (1.6.7)
176 162
       mime-types (>= 1.16)
177 163
     rubyzip (0.9.9)
178  
-    rufus-scheduler (2.0.17)
179  
-      tzinfo (>= 0.3.23)
180  
-    rush (0.6.8)
181  
-      session
182 164
     rvm-capistrano (1.2.5)
183 165
       capistrano (>= 2.0.0)
184 166
     sass (3.1.20)
@@ -191,28 +173,37 @@ GEM
191 173
       libwebsocket (~> 0.1.3)
192 174
       multi_json (~> 1.0)
193 175
       rubyzip
194  
-    session (3.1.0)
195  
-      fattr
196 176
     shoulda (3.1.1)
197 177
       shoulda-context (~> 1.0)
198 178
       shoulda-matchers (~> 1.2)
199 179
     shoulda-context (1.0.0)
200 180
     shoulda-matchers (1.2.0)
201 181
       activesupport (>= 3.0.0)
  182
+    sidekiq (2.5.2)
  183
+      celluloid (~> 0.12.0)
  184
+      connection_pool (~> 0.9.2)
  185
+      multi_json (~> 1)
  186
+      redis (~> 3)
  187
+      redis-namespace
202 188
     sinatra (1.3.3)
203 189
       rack (~> 1.3, >= 1.3.6)
204 190
       rack-protection (~> 1.2)
205 191
       tilt (~> 1.3, >= 1.3.3)
  192
+    slim (1.3.3)
  193
+      temple (~> 0.5.5)
  194
+      tilt (~> 1.3.3)
206 195
     sprockets (2.1.3)
207 196
       hike (~> 1.2)
208 197
       rack (~> 1.0)
209 198
       tilt (~> 1.1, != 1.3.0)
  199
+    temple (0.5.5)
210 200
     thin (1.5.0)
211 201
       daemons (>= 1.0.9)
212 202
       eventmachine (>= 0.12.6)
213 203
       rack (>= 1.0.0)
214 204
     thor (0.15.4)
215 205
     tilt (1.3.3)
  206
+    timers (1.0.1)
216 207
     treetop (1.4.10)
217 208
       polyglot
218 209
       polyglot (>= 0.3.1)
@@ -222,8 +213,6 @@ GEM
222 213
     uglifier (1.2.7)
223 214
       execjs (>= 0.3.0)
224 215
       multi_json (~> 1.3)
225  
-    vegas (0.1.11)
226  
-      rack (>= 1.0.0)
227 216
     will_paginate (3.0.3)
228 217
     xpath (0.1.4)
229 218
       nokogiri (~> 1.3)
@@ -232,6 +221,7 @@ PLATFORMS
232 221
   ruby
233 222
 
234 223
 DEPENDENCIES
  224
+  autoscaler
235 225
   capistrano
236 226
   capybara-webkit
237 227
   coffee-rails (~> 3.2.1)
@@ -242,7 +232,6 @@ DEPENDENCIES
242 232
   goodreads!
243 233
   haml
244 234
   hashie
245  
-  hirefire
246 235
   hpricot
247 236
   jquery-rails
248 237
   json
@@ -252,11 +241,12 @@ DEPENDENCIES
252 241
   oauth
253 242
   pg
254 243
   rails (= 3.2.8)
255  
-  resque (~> 1.22.0)
256  
-  resque-scheduler
257 244
   rvm-capistrano
258 245
   sass-rails (~> 3.2.3)
259 246
   shoulda
  247
+  sidekiq
  248
+  sinatra
  249
+  slim
260 250
   thin
261 251
   turn
262 252
   uglifier (>= 1.0.3)
1  Procfile
... ...
@@ -1,2 +1 @@
1 1
 web: bundle exec rails server thin -p $PORT -e $RACK_ENV 
2  
-resquework: env QUEUE=* TERM_CHILD=1 bundle exec rake resque:work
2  app/controllers/users_controller.rb
@@ -11,7 +11,7 @@ def login
11 11
   def oauth_callback
12 12
     @user = get_authorized_user
13 13
     @user.update_shelves
14  
-    Resque.enqueue(UpdateUser, @user.id)
  14
+    UpdateUser.perform_async @user.id
15 15
 
16 16
     session[:user_id] = @user.id
17 17
     redirect_to :controller => :books, :action => :index
5  app/workers/queue_all_users.rb
... ...
@@ -1,10 +1,9 @@
1 1
 class QueueAllUsers
2  
-  @queue = :lookup
3 2
 
4  
-  def self.perform
  3
+  def perform
5 4
     User.find_each do |user|
6 5
       puts "enqueuing #{user.id} - goodreads id #{user.goodreads_id}"
7  
-      Resque.enqueue(UpdateUser, user.id)
  6
+      UpdateUser.perform_asyn user.id
8 7
     end
9 8
   end
10 9
 end
4  app/workers/update_user.rb
... ...
@@ -1,7 +1,7 @@
1 1
 class UpdateUser
2  
-  @queue = :lookup
  2
+  include Sidekiq::Worker
3 3
 
4  
-  def self.perform(user_id)
  4
+  def perform(user_id)
5 5
     User.find(user_id).update!
6 6
   end
7 7
 end
10  config.ru
... ...
@@ -1,14 +1,14 @@
1 1
 # This file is used by Rack-based servers to start the application.
2 2
 require ::File.expand_path('../config/environment',  __FILE__)
3  
-require 'resque/server'
  3
+require 'sidekiq/web'
4 4
 
5  
-AUTH_PASSWORD = ENV['RESQUE_PASSWORD']
  5
+AUTH_PASSWORD = ENV['SIDEKIQ_PASSWORD']
6 6
 if AUTH_PASSWORD
7  
-  Resque::Server.use Rack::Auth::Basic do |username, password|
  7
+  Sidekiq::Web.use Rack::Auth::Basic do |username, password|
8 8
     password == AUTH_PASSWORD
9 9
   end
10 10
 end
11 11
 
12 12
 run Rack::URLMap.new \
13  
-  "/"       => Minuteman::Application,
14  
-  "/resque" => Resque::Server.new
  13
+  "/"        => Minuteman::Application,
  14
+  "/sidekiq" => Sidekiq::Web
92  config/deploy.rb
... ...
@@ -1,92 +0,0 @@
1  
-#---
2  
-# Excerpted from "Agile Web Development with Rails",
3  
-# published by The Pragmatic Bookshelf.
4  
-# Copyrights apply to this code. It may not be used to create training material, 
5  
-# courses, books, articles, and the like. Contact us if you are in doubt.
6  
-# We make no guarantees that this code is fit for any purpose. 
7  
-# Visit http://www.pragmaticprogrammer.com/titles/rails4 for more book information.
8  
-#---
9  
-# be sure to change these
10  
-set :user, 'tmayfield'
11  
-set :domain, 'zen-hacking.com'
12  
-set :application, 'literate-minuteman'
13  
-
14  
-# adjust if you are using RVM, remove if you are not
15  
-require "rvm/capistrano"
16  
-set :rvm_ruby_string, '1.9.3'
17  
-
18  
-# file paths
19  
-set :repository,  "git@github.com:thegreatape/#{application}.git" 
20  
-set :deploy_to, "/var/www/#{application}" 
21  
-
22  
-# distribute your applications across servers (the instructions below put them
23  
-# all on the same server, defined above as 'domain', adjust as necessary)
24  
-role :app, domain
25  
-role :web, domain
26  
-role :db, domain, :primary => true
27  
-
28  
-# you might need to set this if you aren't seeing password prompts
29  
-# default_run_options[:pty] = true
30  
-
31  
-# As Capistrano executes in a non-interactive mode and therefore doesn't cause
32  
-# any of your shell profile scripts to be run, the following might be needed
33  
-# if (for example) you have locally installed gems or applications.  Note:
34  
-# this needs to contain the full values for the variables set, not simply
35  
-# the deltas.
36  
-# default_environment['PATH']='<your paths>:/usr/local/bin:/usr/bin:/bin'
37  
-# default_environment['GEM_PATH']='<your paths>:/usr/lib/ruby/gems/1.8'
38  
-
39  
-# miscellaneous options
40  
-set :deploy_via, :remote_cache
41  
-set :scm, 'git'
42  
-set :branch, 'master'
43  
-set :scm_verbose, true
44  
-set :use_sudo, false
45  
-set :rails_env, :production
46  
-set :normalize_asset_timestamps, false
47  
-
48  
-namespace :deploy do
49  
-  desc "cause Passenger to initiate a restart"
50  
-  task :restart do
51  
-    run "touch #{current_path}/tmp/restart.txt" 
52  
-  end
53  
-
54  
-  desc "reload the database with seed data"
55  
-  task :seed do
56  
-    run "cd #{current_path}; rake db:seed RAILS_ENV=#{rails_env}"
57  
-  end
58  
-end
59  
-
60  
-after "deploy:update_code", :update_config
61  
-desc "copy prod db config and goodreads keys to deployment"
62  
-task :update_config, :roles => :app do
63  
-  run "cd #{release_path} && cp /var/www/literate-minuteman-database.yml #{release_path}/config/database.yml"
64  
-  run "cd #{release_path} && cp /var/www/goodreads.rb #{release_path}/config/initializers/goodreads.rb"
65  
-end
66  
-
67  
-after "deploy:update_code", :bundle_install
68  
-desc "install the necessary prerequisites"
69  
-task :bundle_install, :roles => :app do
70  
-  run "cd #{release_path} && bundle install --without=test"
71  
-end
72  
-
73  
-after "bundle_install", :precompile_assets
74  
-desc "precompile assets"
75  
-task :precompile_assets, :roles => :app do
76  
-  run "cd #{release_path} && bundle exec rake assets:precompile"
77  
-end
78  
-
79  
-after "precompile_assets", :db_migrate
80  
-desc "run migrations"
81  
-task :db_migrate, :roles => :app do
82  
-  run "cd #{release_path} && RAILS_ENV=production bundle exec rake db:migrate"
83  
-end
84  
-
85  
-after "deploy:restart", :restart_resque
86  
-desc "restart resque"
87  
-task :restart_resque, :roles => :app do
88  
-  run "sudo stop resque-worker"
89  
-  run "sudo start resque-worker"
90  
-  run "sudo stop resque-scheduler"
91  
-  run "sudo start resque-scheduler"
92  
-end
1  config/environments/production.rb
@@ -58,5 +58,4 @@
58 58
   # Send deprecation notices to registered listeners
59 59
   config.active_support.deprecation = :notify
60 60
 
61  
-  Resque.redis = ENV['REDISTOGO_URL'] 
62 61
 end
3  config/initializers/hirefire.rb
... ...
@@ -1,3 +0,0 @@
1  
-HireFire.configure do |config|
2  
-  config.max_workers = 1
3  
-end
16  lib/tasks/resque.rake
... ...
@@ -1,16 +0,0 @@
1  
-require 'resque/tasks'
2  
-require 'resque_scheduler/tasks'    
3  
-
4  
-
5  
-namespace :resque do
6  
-  task :setup => :environment do
7  
-    ENV['QUEUE'] = '*'
8  
-    require 'resque'
9  
-    require 'resque_scheduler'
10  
-    require 'resque/scheduler'      
11  
-    Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
12  
-    Resque.schedule = YAML.load_file("#{Rails.root}/config/resque-schedule.yml")
13  
-  end
14  
-end
15  
-
16  
-

0 notes on commit 2414a61

Please sign in to comment.
Something went wrong with that request. Please try again.