Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support user sync via Sidekiq.

  • Loading branch information...
commit c764d4d28d513347b3c6b6deea573497b90de05c 1 parent 05e7551
@roidrage roidrage authored
View
4 Gemfile
@@ -4,6 +4,7 @@ ruby '1.9.3' rescue nil
gem 'travis-core', git: 'git://github.com/travis-ci/travis-core', require: 'travis/engine'
gem 'travis-support', git: 'git://github.com/travis-ci/travis-support'
+gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs'
gem 'rails', '~> 3.2.3'
gem 'execjs', '1.3.0'
@@ -71,4 +72,7 @@ group :test do
gem 'database_cleaner', '~> 0.7.0'
gem 'mocha', '~> 0.10.0'
gem 'webmock', '~> 1.7.7'
+ gem 'guard'
+ gem 'guard-rspec'
+ gem 'rb-fsevent'
end
View
55 Gemfile.lock
@@ -47,6 +47,14 @@ GIT
thor (~> 0.14.6)
GIT
+ remote: git://github.com/travis-ci/travis-sidekiqs.git
+ revision: 3141f95b3ef38146897a494f3bfa14c1bb02b6c9
+ specs:
+ travis-sidekiqs (0.0.1)
+ sentry-raven
+ sidekiq (~> 2.5.0)
+
+GIT
remote: git://github.com/travis-ci/travis-support
revision: f78d9161369f574f12b9c0c0dbfe13b997766bdd
specs:
@@ -120,9 +128,13 @@ GEM
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
+ celluloid (0.12.3)
+ facter (>= 1.6.12)
+ timers (>= 1.0.0)
childprocess (0.3.6)
ffi (~> 1.0, >= 1.0.6)
chunky_png (1.2.6)
+ coderay (1.0.8)
coffee-script (2.2.0)
coffee-script-source
execjs
@@ -131,6 +143,7 @@ GEM
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
+ connection_pool (0.9.2)
crack (0.3.1)
daemons (1.1.9)
data_migrations (0.0.1)
@@ -147,6 +160,7 @@ GEM
eventmachine (1.0.0)
execjs (1.3.0)
multi_json (~> 1.0)
+ facter (1.6.13)
factory_girl (2.4.2)
activesupport
faraday (0.8.4)
@@ -157,6 +171,13 @@ GEM
thor (>= 0.13.6)
forgery (0.5.0)
fssm (0.2.9)
+ guard (1.5.3)
+ listen (>= 0.4.2)
+ lumberjack (>= 1.0.2)
+ pry (>= 0.9.10)
+ thor (>= 0.14.6)
+ guard-rspec (1.2.1)
+ guard (>= 1.1)
hashie (1.2.0)
hashr (0.0.22)
hike (1.2.1)
@@ -169,14 +190,17 @@ GEM
kgio (2.7.4)
libwebsocket (0.1.5)
addressable
+ listen (0.5.3)
lograge (0.0.6)
actionpack
activesupport
+ lumberjack (1.0.2)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
metaclass (0.0.1)
+ method_source (0.8.1)
metriks (0.9.9.2)
atomic (~> 1.0)
avl_tree (~> 1.1.2)
@@ -213,6 +237,10 @@ GEM
actionmailer
postmark (>= 0.9.0)
rake
+ pry (0.9.10)
+ coderay (~> 1.0.5)
+ method_source (~> 0.8)
+ slop (~> 3.3.1)
pusher (0.9.4)
multi_json (~> 1.0)
signature (~> 0.1.2)
@@ -240,9 +268,12 @@ GEM
thor (>= 0.14.6, < 2.0)
raindrops (0.10.0)
rake (0.9.2.2)
+ rb-fsevent (0.9.2)
rdoc (3.12)
json (~> 1.4)
redis (3.0.2)
+ redis-namespace (1.2.1)
+ redis (~> 3.0.0)
refraction (0.2.0)
rollout (1.1.0)
rspec (2.10.0)
@@ -265,14 +296,32 @@ GEM
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
+ sentry-raven (0.3)
+ faraday (~> 0.8.0.rc2)
+ hashie
+ multi_json (~> 1.0)
+ uuidtools
+ sidekiq (2.5.1)
+ celluloid (~> 0.12.0)
+ compass
+ connection_pool (~> 0.9.2)
+ multi_json (~> 1)
+ redis (~> 3)
+ redis-namespace
+ sass
+ sprockets-sass
signature (0.1.4)
simple_states (0.1.1)
activesupport
hashr (~> 0.0.10)
+ slop (3.3.3)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
+ sprockets-sass (0.9.1)
+ sprockets (~> 2.0)
+ tilt (~> 1.1)
term-ansicolor (1.0.7)
thin (1.3.1)
daemons (>= 1.0.9)
@@ -280,6 +329,7 @@ GEM
rack (>= 1.0.0)
thor (0.14.6)
tilt (1.3.3)
+ timers (1.0.1)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
@@ -289,6 +339,7 @@ GEM
rack
raindrops (~> 0.6)
unobtrusive_flash (0.0.2)
+ uuidtools (2.1.3)
versionist (0.2.4)
rails (~> 3.0)
yard (~> 0.7)
@@ -318,6 +369,8 @@ DEPENDENCIES
foreman (~> 0.36.0)
forgery (~> 0.5.0)
gh!
+ guard
+ guard-rspec
http_accept_language (~> 1.0.2)
hubble!
json (~> 1.6.3)
@@ -334,11 +387,13 @@ DEPENDENCIES
rake (~> 0.9.2.2)
rake-pipeline!
rake-pipeline-web-filters!
+ rb-fsevent
refraction (~> 0.2.0)
rspec-rails (~> 2.10.0)
thin (~> 1.3.1)
travis-assets!
travis-core!
+ travis-sidekiqs!
travis-support!
unicorn (~> 4.1.1)
unobtrusive_flash (~> 0.0.2)
View
24 Guardfile
@@ -0,0 +1,24 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+
+ # Capybara request specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+
+ # Turnip features and steps
+ watch(%r{^spec/acceptance/(.+)\.feature$})
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
+end
+
View
10 app/helpers/sync_helper.rb
@@ -1,9 +1,15 @@
module SyncHelper
def sync_user(user)
unless user.is_syncing?
- publisher = Travis::Amqp::Publisher.new('sync.user')
- publisher.publish({ user_id: user.id }, type: 'sync')
+ if Travis::Features.enabled_for_all?(:sync_via_sidekiq)
+ Travis::Sidekiq::SynchronizeUser.perform_async(user_id: user.id)
+ else
+ publisher = Travis::Amqp::Publisher.new('sync.user')
+ publisher.publish({ user_id: user.id }, type: 'sync')
+ end
user.update_column(:is_syncing, true)
end
+ rescue => error
+ user.update_column(:is_syncing, false)
end
end
View
2  config/initializers/sidekiq.rb
@@ -0,0 +1,2 @@
+require 'sidekiq'
+require 'travis/sidekiq/workers'
View
19 create-queues.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+
+require 'bundler/setup'
+require 'bunny'
+
+amqp = ARGV[0]
+
+# amqp://gzqeyzpl:nTrc8hRERCiupG9e@qqkkcunk.rabbitmq-bigwig.lshift.net:17335/qqkkc unk
+
+puts amqp
+
+bunny = Bunny.new(amqp)
+bunny.start
+
+exchange = bunny.exchange('reporting', type: :topic, durable: true)
+
+%w{builds.common builds.jvmotp builds.php builds.rails builds.requests builds.spree reporting.jobs.builds.common reporting.jobs.builds.jvmotp reporting.jobs.builds.php reporting.jobs.builds.rails reporting.jobs.builds.spree reporting.jobs.logs reporting.jobs.logs.0 reporting.jobs.logs.1 reporting.jobs.logs.2 reporting.jobs.logs.3 reporting.jobs.logs.4 reporting.jobs.logs.5 reporting.jobs.logs.6 reporting.jobs.logs.7 reporting.jobs.logs.8 reporting.jobs.logs.9 reporting.workers sync.user}.each do |queue_name|
+ bunny.queue(queue_name, durable: true)
+end
View
32 spec/controllers/profiles_controller_spec.rb
@@ -32,6 +32,12 @@
Travis::Amqp::Publisher.stubs(:new).returns(publisher)
end
+ it "should reset the user's syncing flag when an error occurs" do
+ publisher.expects(:publish).raises(StandardError)
+ post :sync
+ user.reload.is_syncing.should == false
+ end
+
describe 'given the current user is not being synced' do
before :each do
user.update_column(:is_syncing, false)
@@ -63,5 +69,31 @@
post :sync
end
end
+
+ describe 'with sidekiq enabled' do
+ before do
+ user.update_column(:is_syncing, false)
+ Travis::Features.enable_for_all(:sync_via_sidekiq)
+ end
+
+ after do
+ Travis::Features.disable_for_all(:sync_via_sidekiq)
+ end
+
+ it "should publish to sidekiq" do
+ Travis::Sidekiq::SynchronizeUser.expects(:perform_async)
+ post :sync
+ end
+
+ it "shouldn't publish to amqp" do
+ publisher.expects(:publish).never
+ post :sync
+ end
+
+ it "should set the user to syncing" do
+ post :sync
+ user.reload.is_syncing.should == true
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.