2012-04-12 11:29:04 +01:00
|
|
|
class BuildListObserver < ActiveRecord::Observer
|
|
|
|
observe :build_list
|
|
|
|
|
|
|
|
def before_update(record)
|
|
|
|
if record.status_changed?
|
|
|
|
record.started_at = Time.now if record.status == BuildServer::BUILD_STARTED
|
|
|
|
if [BuildServer::BUILD_ERROR, BuildServer::SUCCESS].include? record.status
|
|
|
|
# stores time interval beetwin build start and finish in seconds
|
2012-04-12 15:55:32 +01:00
|
|
|
record.duration = record.current_duration
|
2012-04-13 14:24:43 +01:00
|
|
|
|
|
|
|
if record.status == BuildServer::SUCCESS
|
|
|
|
# Update project average build time
|
|
|
|
av_time = record.project.average_build_time
|
|
|
|
n = record.project.build_count
|
|
|
|
new_av_time = ( av_time * n + record.duration ) / ( n + 1 )
|
|
|
|
record.project.update_attribute(:average_build_time, new_av_time)
|
|
|
|
record.project.update_attribute(:build_count, n + 1 )
|
|
|
|
end
|
2012-04-12 11:29:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|