Permalink
Please sign in to comment.
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...
Showing
with
152 additions
and 17 deletions.
- +1 −1 Gemfile
- +8 −8 Gemfile.lock
- +6 −5 lib/travis/hub.rb
- +6 −3 lib/travis/hub/handler.rb
- +46 −0 lib/travis/hub/handler/configure.rb
- +85 −0 spec/travis/hub/handler/configure_spec.rb
16
Gemfile.lock
@@ -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