ensure that the Time.now builds get started and tag the Sentry errors from cron

This commit is contained in:
Renée Hendricksen 2016-08-02 19:44:33 -04:00
parent 75bd65e56c
commit d0a143d76a
4 changed files with 18 additions and 11 deletions

View File

@ -13,7 +13,7 @@ module Travis::API::V3
elsif last_cron_build_date >= planned_time(LastBuild) elsif last_cron_build_date >= planned_time(LastBuild)
planned_time(ThisBuild) planned_time(ThisBuild)
else else
Time.now Time.now - 5.minutes
end end
end end

View File

@ -7,10 +7,11 @@ module Travis::API::V3
def start_all() def start_all()
Models::Cron.all.select do |cron| Models::Cron.all.select do |cron|
@cron = cron
start(cron) if cron.next_enqueuing <= Time.now start(cron) if cron.next_enqueuing <= Time.now
end end
rescue => e rescue => e
Raven.capture_exception(e) Raven.capture_exception(e, tags: { 'cron_id' => @cron.try(:id) })
end end
def start(cron) def start(cron)

View File

@ -43,11 +43,13 @@ describe Travis::API::V3::Models::Cron do
describe "push build is ignored if disable by build is false" do describe "push build is ignored if disable by build is false" do
before do before do
Timecop.return
Timecop.travel(DateTime.new(2015, 12, 31, 16)) Timecop.travel(DateTime.new(2015, 12, 31, 16))
end end
after do after do
Timecop.return Timecop.return
Timecop.freeze(Time.now.utc)
end end
it "for daily builds" do it "for daily builds" do
@ -85,11 +87,13 @@ describe Travis::API::V3::Models::Cron do
describe "disable by build works with build" do describe "disable by build works with build" do
before do before do
Timecop.return
Timecop.travel(DateTime.new(2015, 12, 31, 16)) Timecop.travel(DateTime.new(2015, 12, 31, 16))
end end
after do after do
Timecop.return Timecop.return
Timecop.freeze(Time.now.utc)
end end
it "for daily builds" do it "for daily builds" do
@ -121,11 +125,13 @@ describe Travis::API::V3::Models::Cron do
describe "disable by build works without build" do describe "disable by build works without build" do
before do before do
Timecop.return
Timecop.travel(DateTime.new(2015, 12, 31, 16)) Timecop.travel(DateTime.new(2015, 12, 31, 16))
end end
after do after do
Timecop.return Timecop.return
Timecop.freeze(Time.now.utc)
end end
it "for daily builds" do it "for daily builds" do
@ -157,12 +163,12 @@ describe Travis::API::V3::Models::Cron do
describe "build starts now if next build time is in the past" do describe "build starts now if next build time is in the past" do
before do before do
# nothing, this time Timecop.return
# time freeze is performed in examples
end end
after do after do
Timecop.return Timecop.return
Timecop.freeze(Time.now.utc)
end end
it "for daily builds with disable_by_build true" do it "for daily builds with disable_by_build true" do
@ -170,7 +176,7 @@ describe Travis::API::V3::Models::Cron do
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'daily', disable_by_build: true) cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'daily', disable_by_build: true)
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron') build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
Timecop.freeze(DateTime.new(2016, 1, 1, 19)) Timecop.freeze(DateTime.new(2016, 1, 1, 19))
expect(cron.next_enqueuing).to be == DateTime.now expect(cron.next_enqueuing).to be == DateTime.now - 5.minutes
build.destroy build.destroy
cron.destroy cron.destroy
end end
@ -180,7 +186,7 @@ describe Travis::API::V3::Models::Cron do
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'daily', disable_by_build: false) cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'daily', disable_by_build: false)
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron') build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
Timecop.freeze(DateTime.new(2016, 1, 1, 19)) Timecop.freeze(DateTime.new(2016, 1, 1, 19))
expect(cron.next_enqueuing).to be == DateTime.now expect(cron.next_enqueuing).to be == DateTime.now - 5.minutes
build.destroy build.destroy
cron.destroy cron.destroy
end end
@ -190,7 +196,7 @@ describe Travis::API::V3::Models::Cron do
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'weekly', disable_by_build: true) cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'weekly', disable_by_build: true)
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron') build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
Timecop.freeze(DateTime.new(2016, 1, 7, 19)) Timecop.freeze(DateTime.new(2016, 1, 7, 19))
expect(cron.next_enqueuing).to be == DateTime.now expect(cron.next_enqueuing).to be == DateTime.now - 5.minutes
build.destroy build.destroy
cron.destroy cron.destroy
end end
@ -200,7 +206,7 @@ describe Travis::API::V3::Models::Cron do
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'weekly', disable_by_build: false) cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'weekly', disable_by_build: false)
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron') build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
Timecop.freeze(DateTime.new(2016, 1, 7, 19)) Timecop.freeze(DateTime.new(2016, 1, 7, 19))
expect(cron.next_enqueuing).to be == DateTime.now expect(cron.next_enqueuing).to be == DateTime.now - 5.minutes
build.destroy build.destroy
cron.destroy cron.destroy
end end
@ -210,7 +216,7 @@ describe Travis::API::V3::Models::Cron do
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'monthly', disable_by_build: true) cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'monthly', disable_by_build: true)
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron') build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
Timecop.freeze(DateTime.new(2016, 1, 31, 19)) Timecop.freeze(DateTime.new(2016, 1, 31, 19))
expect(cron.next_enqueuing).to be == DateTime.now expect(cron.next_enqueuing).to be == DateTime.now - 5.minutes
build.destroy build.destroy
cron.destroy cron.destroy
end end
@ -220,7 +226,7 @@ describe Travis::API::V3::Models::Cron do
cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'monthly', disable_by_build: false) cron = Travis::API::V3::Models::Cron.create(branch_id: branch.id, interval: 'monthly', disable_by_build: false)
build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron') build = Travis::API::V3::Models::Build.create(:repository_id => repo.id, :branch_name => branch.name, :event_type => 'cron')
Timecop.freeze(DateTime.new(2016, 1, 31, 19)) Timecop.freeze(DateTime.new(2016, 1, 31, 19))
expect(cron.next_enqueuing).to be == DateTime.now expect(cron.next_enqueuing).to be == DateTime.now - 5.minutes
build.destroy build.destroy
cron.destroy cron.destroy
end end

View File

@ -26,7 +26,7 @@ describe Travis::API::V3::Queries::Crons do
cron = Travis::API::V3::Models::Cron.create(branch_id: existing_branch.id, interval: 'daily', disable_by_build: false) cron = Travis::API::V3::Models::Cron.create(branch_id: existing_branch.id, interval: 'daily', disable_by_build: false)
error = StandardError.new('Konstantin broke all the thingz!') error = StandardError.new('Konstantin broke all the thingz!')
Travis::API::V3::Models::Cron.any_instance.stubs(:branch).raises(error) Travis::API::V3::Models::Cron.any_instance.stubs(:branch).raises(error)
Raven.expects(:capture_exception).with(error) Raven.expects(:capture_exception).with(error, tags: {'cron_id' => cron.id })
query.start_all query.start_all
end end
end end