Skip to content

Commit

Permalink
Merge pull request #39 from RodrigoMNardi/bug/workers/watchdog_missin…
Browse files Browse the repository at this point in the history
…g_stage

Watchdog - Check if missing stage
  • Loading branch information
RodrigoMNardi authored Dec 27, 2023
2 parents ee147f2 + 20fb487 commit 0aeef6d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
14 changes: 13 additions & 1 deletion lib/github/build/summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

require_relative '../../github/check'
require_relative '../../bamboo_ci/download'
require_relative '../../bamboo_ci/running_plan'

module Github
module Build
Expand Down Expand Up @@ -223,13 +224,24 @@ def build_message(job)
def fetch_parent_stage
jobs = BambooCi::RunningPlan.fetch(@check_suite.bamboo_ci_ref)
info = jobs.find { |job| job[:name] == @job.name }
stage = Stage.find_by(check_suite: @check_suite, name: info[:stage])

stage = first_or_create_stage(info)

logger(Logger::INFO, "fetch_parent_stage - stage: #{stage.inspect} info[:stage]: #{info[:stage]}")

@job.update(stage: stage)

stage
end

def first_or_create_stage(info)
config = StageConfiguration.find_by(bamboo_stage_name: info[:stage])
stage = Stage.find_by(check_suite: @check_suite, name: info[:stage])
stage = Stage.create(check_suite: @check_suite, name: info[:stage], configuration: config) if stage.nil?

stage
end

def logger(severity, message)
@loggers.each do |logger_object|
logger_object.add(severity, message)
Expand Down
12 changes: 2 additions & 10 deletions lib/models/ci_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,8 @@ class CiJob < ActiveRecord::Base
scope :not_skipped, -> { where.not(status: 'skipped') }
scope :failure, -> { where(status: %i[failure cancelled skipped]) }

def checkout_code?
name.downcase.match? 'checkout'
end

def build?
name.downcase.match? 'build'
end

def test?
!build? and !checkout_code?
def finished?
!%w[queued in_progress].include?(status)
end

def create_check_run
Expand Down
1 change: 1 addition & 0 deletions workers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require_relative '../lib/bamboo_ci/api'
require_relative '../lib/github/check'
require_relative '../lib/helpers/configuration'
require_relative '../lib/github_ci_app'

class Base
include BambooCi::Api
Expand Down
10 changes: 2 additions & 8 deletions workers/watch_dog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ def check(suites)
end
end

def finish_stages(check_suite)
check_suite.ci_jobs.stages.each do |stage|
summary = Github::Build::Summary.new(stage)
summary.missing_stage(stage)
end
end

# Checks if CI still running
def in_progress?(build_status)
return false if ci_stopped?(build_status)
return false if ci_hanged?(build_status)
Expand All @@ -62,7 +56,7 @@ def in_progress?(build_status)
end

def ci_stopped?(build_status)
build_status.key?('message') and !build_status.key? 'finished'
build_status.key?('message') and !build_status.key?('finished')
end

def ci_hanged?(build_status)
Expand Down

0 comments on commit 0aeef6d

Please sign in to comment.