Skip to content

Commit

Permalink
[FIXUP] BuildFailure performance refactor pt.2
Browse files Browse the repository at this point in the history
  • Loading branch information
NickLaMuro committed Jan 15, 2020
1 parent 5d920e4 commit 6ec3222
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions app/workers/travis_branch_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,29 @@ def process_repo(repo)
end

def process_branch(repo, branch)
v3_client = TravisV3Client.new(:repo => Travis::Repository.find(repo.name))
branch_record = repo.regular_branches.where(:name => branch).first
branch_builds = v3_client.repo_branch_builds(branch)
failure = BuildFailure.where(:repo => repo, :branch => branch_record).first

# If we already have a failure record, call notify with that record
return failure.notify if failure

# otherwise, check if any builds exist with a failures, and if so, create a
# new BuildFailure record.
v3_client = TravisV3Client.new(:repo => Travis::Repository.find(repo.name))
branch_builds = v3_client.repo_branch_builds(branch)

if branch_builds.first.failed?
first_failure = find_first_recent_failure(branch_builds)
failure ||= BuildFailure.create(:repo => repo,
:branch => branch_record,
failure = BuildFailure.create(:repo => repo,
:branch => branch,
:travis_build_id => first_failure.id)

failure.notify
elsif failure
post_passing(failure)
end
end

private

def post_passing(failure)
BuildFailureNotifier.new(failure).report_passing
failure.delete
end

def find_first_recent_failure(builds)
first_recent_failure = nil
builds.each do |build|
Expand Down

0 comments on commit 6ec3222

Please sign in to comment.