Class: CruiseFace::Model::Stage

Inherits:
Object
  • Object
show all
Defined in:
lib/cruise_face/stage.rb

Defined Under Namespace

Classes: History

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, pipelines) ⇒ Stage

Returns a new instance of Stage.



70
71
72
73
# File 'lib/cruise_face/stage.rb', line 70

def initialize(config, pipelines)
  @config = config
  @history = History.new(pipelines.collect { |pipeline| pipeline.stages[name] }.reject {|history_stage| history_stage.unknown? })
end

Instance Attribute Details

#historyObject (readonly)

Returns the value of attribute history.



68
69
70
# File 'lib/cruise_face/stage.rb', line 68

def history
  @history
end

Instance Method Details

#building?Boolean

Returns:

  • (Boolean)


83
84
85
86
# File 'lib/cruise_face/stage.rb', line 83

def building?
  return false if no_history?
  @history.first.building?
end

#building_jobsObject



88
89
90
91
# File 'lib/cruise_face/stage.rb', line 88

def building_jobs
  return [] if no_history?
  @history.first.jobs.select(&:incompleted?)
end

#find_broking_builds_committers(failed_job) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/cruise_face/stage.rb', line 123

def find_broking_builds_committers(failed_job)
  broken_jobs = []
  self.history.failed_jobs_from_now_until_passed(failed_job.name).each do |job|
    if job.failed?
      broken_jobs << job
    else
      break
    end
  end
  broken_jobs.collect(&:stage).collect(&:committers).flatten.uniq
end

#latest_committersObject



93
94
95
96
# File 'lib/cruise_face/stage.rb', line 93

def latest_committers
  return ['Unknown'] if no_history?
  @history.first.committers
end

#manual?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/cruise_face/stage.rb', line 79

def manual?
  @config.isAutoApproved == 'false'
end

#nameObject



75
76
77
# File 'lib/cruise_face/stage.rb', line 75

def name
  @config.name
end

#no_history?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/cruise_face/stage.rb', line 98

def no_history?
  @history.first.blank?
end

#progressObject

from 0 to 100, as 0% to 100% when 1 building job

> (building job current_build_duration/last_build_duration) * 100

when 2 building job

time left = [(job2.last_build_duration - job2.current_build_duration), (job1.last_build_duration - job1.current_build_duration)].max
time built = [job2.current_build_duration, job1.current_build_duration].max

> (time left / (time left + time built)) * 100

when 1 building job1, 1 scheduled job2

time left = job2.last_build_duration + (job1.last_build_duration - job1.current_build_duration)
time built = job1.current_build_duration

> (time left / (time left + time built)) * 100

when 0 building job, 1 scheduled job

> 0

when 0 building job, 1 completed job1, 1 scheduled job2

time left = job2.last_build_duration
time built = job1.current_build_duration

> (time left / (time left + time built)) * 100

when 0 building job, 2 completed job1 & job2, 1 scheduled job3

time left = job3.last_build_duration
time built = job1.current_build_duration + job2.current_build_duration

> (time left / (time left + time built)) * 100

when 1 building job0, 2 completed job1 & job2, 1 scheduled job3

time left = job3.last_build_duration + (job0.last_build_duration - job0.current_build_duration)
time built = job1.current_build_duration + job2.current_build_duration + job0.current_build_duration

> (time left / (time left + time built)) * 100



160
161
162
163
164
# File 'lib/cruise_face/stage.rb', line 160

def progress
  return 100 unless @history.first
  completed_size = @history.first.jobs.select(&:completed?).size
  completed_size * 100 / @history.first.jobs.size
end

#to_xml(xm) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/cruise_face/stage.rb', line 102

def to_xml(xm)
  xm.stage(:name => self.name) do
    xm.latest(:status => self.history.status) do
      xm.failed(self.history.failed?, :type => 'boolean')
      xm.committers(:type => 'array') do
        self.latest_committers.each { |committer| xm.committer(:name => committer) }
      end
    end
    xm.building_jobs(:type => 'array') do
      self.building_jobs.each { |job| xm.job(:name => job.name) }
    end
    xm.failing_jobs(:type => 'array') do
      self.history.as_jobs.select(&:failed?).each do |job|
        xm.job(:name => job.name) do
          xm.committers(:type => 'array') { find_broking_builds_committers(job).each { |committer| xm.committer(:name => committer) } }
        end
      end
    end
  end
end