Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Commit

Permalink
Don't run projects which are assigned to specific runner by shared ru…
Browse files Browse the repository at this point in the history
…nner.
  • Loading branch information
Kamil Trzcinski authored and ayufan committed Nov 7, 2014
1 parent aec1d18 commit cbf8711
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
@@ -1,6 +1,7 @@
v5.2
- Improve performance by adding new indicies
- Separate Commit logic from Build logic in prep for Parallel Builds
- Shared runners builds projects which are not assigned to specific ones

v5.1
- Registration token and runner token are named differently
Expand Down
5 changes: 4 additions & 1 deletion lib/api/builds.rb
Expand Up @@ -15,8 +15,11 @@ class Builds < Grape::API

ActiveRecord::Base.transaction do
build = if current_runner.shared?
Build.first_pending
# don't run projects which are assigned to specific runners
projects = RunnerProject.distinct(:project).pluck(:project_id)
Build.where.not(project_id: projects).first_pending
else
# do run projects which are only assigned to this runner
commits = Commit.where(project_id: current_runner.projects)
Build.where(commit_id: commits).first_pending
end
Expand Down
21 changes: 21 additions & 0 deletions spec/requests/api/builds_spec.rb
Expand Up @@ -7,6 +7,9 @@
let(:project) { FactoryGirl.create(:project) }

describe "Builds API for runners" do
let(:shared_runner) { FactoryGirl.create(:runner, token: "SharedRunner") }
let(:shared_project) { FactoryGirl.create(:project, name: "SharedProject") }

before do
FactoryGirl.create :runner_project, project_id: project.id, runner_id: runner.id
end
Expand All @@ -27,6 +30,24 @@

response.status.should == 404
end

it "should return 404 error if no builds for specific runner" do
commit = FactoryGirl.create(:commit, project: shared_project)
build = FactoryGirl.create(:build, commit: commit, status: 'pending' )

post api("/builds/register"), token: runner.token

response.status.should == 404
end

it "should return 404 error if no builds for shared runner" do
commit = FactoryGirl.create(:commit, project: project)
build = FactoryGirl.create(:build, commit: commit, status: 'pending' )

post api("/builds/register"), token: shared_runner.token

response.status.should == 404
end
end

describe "PUT /builds/:id" do
Expand Down

0 comments on commit cbf8711

Please sign in to comment.