summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2015-01-07 12:00:04 -0800
committerValery Sizov <valery@gitlab.com>2015-01-07 13:27:02 -0800
commit9d898f8b0508f43dfffb694d5f480a09bf400a0f (patch)
tree666345dd39ef5a6116776d8edea9b99291e54435
parent01333d40882bfb1d05ba5d0cca2ded0c461aac9a (diff)
downloadgitlab-ci-9d898f8b0508f43dfffb694d5f480a09bf400a0f.tar.gz
Fix scheduled retrying
-rw-r--r--app/models/commit.rb6
-rw-r--r--db/schema.rb2
-rw-r--r--lib/scheduler.rb8
-rw-r--r--spec/models/commit_spec.rb13
4 files changed, 24 insertions, 5 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index f698e39..0e10033 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -34,6 +34,12 @@ class Commit < ActiveRecord::Base
builds.last
end
+ def retry
+ builds_without_retry.each do |build|
+ Build.retry(build)
+ end
+ end
+
def valid_commit_sha
if self.sha == Git::BLANK_SHA
self.errors.add(:sha, " cant be 00000000 (branch removal)")
diff --git a/db/schema.rb b/db/schema.rb
index ad34ec0..2993509 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -30,8 +30,8 @@ ActiveRecord::Schema.define(version: 20141201153755) do
t.string "before_sha"
t.text "push_data"
t.integer "runner_id"
- t.float "coverage"
t.integer "commit_id"
+ t.float "coverage"
t.text "commands"
t.integer "job_id"
end
diff --git a/lib/scheduler.rb b/lib/scheduler.rb
index 0fa7638..6c17f3f 100644
--- a/lib/scheduler.rb
+++ b/lib/scheduler.rb
@@ -2,12 +2,12 @@ class Scheduler
def perform
projects = Project.where(always_build: true).all
projects.each do |project|
- last_build = project.last_build
- next unless last_build
+ last_commit = project.commits.last
+ next unless last_commit
interval = project.polling_interval
- if (last_build.created_at + interval.hours) < Time.now
- Build.create_from(last_build)
+ if (last_commit.last_build.created_at + interval.hours) < Time.now
+ last_commit.retry
puts "."
end
end
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index 430f62f..79cec87 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -49,6 +49,19 @@ describe Commit do
it('returns with the most recently created build') { should eq(@second) }
end
+ describe :retry do
+ before do
+ @first = FactoryGirl.create :build, commit: commit, created_at: Date.yesterday
+ @second = FactoryGirl.create :build, commit: commit
+ end
+
+ it "creates new build" do
+ commit.builds.count.should == 2
+ commit.retry
+ commit.builds.count.should == 3
+ end
+ end
+
describe :ci_skip? do
let(:project) { FactoryGirl.create(:project) }
let(:commit) { FactoryGirl.create(:commit, project: project) }