Permalink
Browse files

Merge pull request #7 from travis-ci/process_configure_jobs

configure jobs can now be processed by the hub instead of by the workers
  • Loading branch information...
joshk committed Apr 26, 2012
2 parents 45d25e2 + aa5e7e5 commit ab141f2cfa43f8482f98ad280ae8df9e47a60739
Showing with 152 additions and 17 deletions.
  1. +1 −1 Gemfile
  2. +8 −8 Gemfile.lock
  3. +6 −5 lib/travis/hub.rb
  4. +6 −3 lib/travis/hub/handler.rb
  5. +46 −0 lib/travis/hub/handler/configure.rb
  6. +85 −0 spec/travis/hub/handler/configure_spec.rb
View
@@ -1,6 +1,6 @@
source :rubygems
-gem 'travis-core', :git => "git://github.com/travis-ci/travis-core", :require => 'travis/engine'
+gem 'travis-core', :git => "git://github.com/travis-ci/travis-core"
gem 'travis-support', :git => "git://github.com/travis-ci/travis-support"
gem 'gh', :git => 'git://github.com/rkh/gh'
View
@@ -14,7 +14,7 @@ GIT
GIT
remote: git://github.com/rkh/gh
- revision: a25f590b31b4b7af92a3ffcfc13d5bf05c0653b4
+ revision: a938b67c5f5a44940494b258b84775b0429315df
specs:
gh (0.3.0)
backports (~> 2.3)
@@ -23,7 +23,7 @@ GIT
GIT
remote: git://github.com/travis-ci/travis-core
- revision: 52fb894cd0d4d211b921e58e111a9ccc7f932800
+ revision: 816fc5cb3cd187424a8b7a7c112c1e8a03ec8996
specs:
travis-core (0.0.1)
actionmailer (~> 3.2.3)
@@ -40,7 +40,7 @@ GIT
rake (~> 0.9.2.2)
redis (~> 2.2.2)
rollout (~> 1.1.0)
- simple_states (~> 0.1.0.pre2)
+ simple_states (= 0.1.0.pre2)
thor (~> 0.14.6)
GIT
@@ -82,8 +82,8 @@ GEM
multi_json (~> 1.0)
addressable (2.2.7)
arel (3.0.2)
- atomic (1.0.0)
- atomic (1.0.0-java)
+ atomic (1.0.1)
+ atomic (1.0.1-java)
avl_tree (1.1.2)
backports (2.5.1)
bouncy-castle-java (1.5.0146.1)
@@ -119,7 +119,7 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
metaclass (0.0.1)
- metriks (0.9.7.3)
+ metriks (0.9.8)
atomic (~> 1.0)
avl_tree (~> 1.1.2)
hitimes (~> 1.1)
@@ -128,7 +128,7 @@ GEM
metaclass (~> 0.0.1)
multi_json (1.0.4)
multipart-post (1.1.5)
- newrelic_rpm (3.3.3)
+ newrelic_rpm (3.3.4.1)
octokit (0.6.5)
addressable (~> 2.2.6)
faraday (~> 0.7.4)
@@ -180,7 +180,7 @@ GEM
simple_states (0.1.0.pre2)
activesupport
hashr (~> 0.0.10)
- sprockets (2.1.2)
+ sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
View
@@ -71,15 +71,16 @@ def run_periodically(interval, &block)
def subscribe
info 'Subscribing to amqp ...'
- subscribe_to_build_requests
+ subscribe_to_build_requests_and_configure_builds
subscribe_to_reporting
subscribe_to_worker_status
end
- def subscribe_to_build_requests
- queue = "builds.requests"
- info "Subscribing to #{queue}"
- Travis::Amqp::Consumer.new(queue).subscribe(:ack => true, &method(:receive))
+ def subscribe_to_build_requests_and_configure_builds
+ ["builds.requests", "builds.configure"].each do |queue|
+ info "Subscribing to #{queue}"
+ Travis::Amqp::Consumer.new(queue).subscribe(:ack => true, &method(:receive))
+ end
end
def subscribe_to_reporting
@@ -3,9 +3,10 @@
module Travis
class Hub
class Handler
- autoload :Job, 'travis/hub/handler/job'
- autoload :Request, 'travis/hub/handler/request'
- autoload :Worker, 'travis/hub/handler/worker'
+ autoload :Configure, 'travis/hub/handler/configure'
+ autoload :Job, 'travis/hub/handler/job'
+ autoload :Request, 'travis/hub/handler/request'
+ autoload :Worker, 'travis/hub/handler/worker'
include Logging
@@ -18,6 +19,8 @@ def for(event, payload)
Handler::Worker.new(event, payload)
when /^request/
Handler::Request.new(event, payload)
+ when /^configure/
+ Handler::Configure.new(event, payload)
else
raise "Unknown message type: #{event.inspect}"
end
@@ -0,0 +1,46 @@
+require 'metriks'
+
+module Travis
+ class Hub
+ class Handler
+ class Configure < Handler
+ def handle
+ track_event(:received)
+ configure_build
+ track_event(:completed)
+ rescue StandardError => e
+ track_event(:failed)
+ raise
+ end
+
+ protected
+
+ def configure_build
+ debug "Retrieving .travis.yml for payload #{payload.inspect}"
+ result = ::Travis::Tasks::ConfigureBuild.new(commit_details).run
+ update_job(result)
+ end
+
+ def update_job(result)
+ debug "Updating Job (id:#{job_id}) with #{result.inspect}"
+ job = ::Job.find(job_id)
+ job.update_attributes(result)
+ end
+
+ def commit_details
+ payload[:build]
+ end
+
+ def job_id
+ payload[:build][:id]
+ end
+
+ def track_event(name)
+ meter_name = 'travis.hub.configure'
+ meter_name = "#{meter_name}.#{name.to_s}"
+ Metriks.meter(meter_name).mark
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,85 @@
+require 'spec_helper'
+
+describe Travis::Hub::Handler::Configure do
+ let(:subject) { Travis::Hub::Handler::Configure.new(:configure, Hashr.new(payload)) }
+ let(:payload) do
+ {
+ 'type' => 'configure',
+ 'repository' => { 'slug' => 'travis-ci/travis-ci' },
+ 'build' => { 'id' => 1, 'commit' => '313f61b', 'config_url' => 'https://raw.github.com/travis-ci/travis-ci/313f61b/.travis.yml' }
+ }
+ end
+ let(:result) do
+ {
+ 'id' => 1,
+ 'config' => {
+ 'script' => 'rake',
+ 'rvm' => ['1.8.7', '1.9.2'],
+ 'gemfile' => ['gemfiles/rails-2.3.x', 'gemfiles/rails-3.0.x']
+ }
+ }
+ end
+
+ describe '#handle' do
+ describe 'sucessful configure' do
+ before(:each) do
+ ::Travis::Tasks::ConfigureBuild.any_instance.expects(:run).returns(result)
+ job = mock()
+ job.expects(:update_attributes).returns(true)
+ ::Job.expects(:find).with(result['id']).returns(job)
+ end
+
+ it "retrieves the config and updates the job" do
+ subject.handle
+ end
+ end
+
+ describe 'failed configure' do
+ before(:each) do
+ ::Travis::Tasks::ConfigureBuild.any_instance.expects(:run).raises(StandardError)
+ end
+
+ it "lets the error proporgate" do
+ expect {
+ subject.handle
+ }.to raise_error(StandardError)
+ end
+ end
+ end
+
+ describe 'metrics' do
+ before(:each) do
+ ::Travis::Tasks::ConfigureBuild.any_instance.stubs(:run).returns({})
+ job = mock()
+ job.stubs(:update_attributes).returns(true)
+ ::Job.stubs(:find).returns(job)
+ end
+
+ it "increments a counter when a configure message is received" do
+ expect {
+ subject.handle
+ }.to change {
+ Metriks.meter('travis.hub.configure.received').count
+ }
+ end
+
+ it "increments a counter when a configure message is completed" do
+ ::Travis::Tasks::ConfigureBuild.stubs(:run).raises(StandardError)
+ expect {
+ subject.handle
+ }.to change {
+ Metriks.meter('travis.hub.configure.completed').count
+ }
+ end
+
+ it "increments a counter when processing a configure message raises an exception" do
+ ::Travis::Tasks::ConfigureBuild.any_instance.stubs(:run).raises(StandardError)
+ expect {
+ subject.handle rescue nil
+ }.to change {
+ Metriks.meter('travis.hub.configure.failed').count
+ }
+ end
+ end
+end
+

0 comments on commit ab141f2

Please sign in to comment.