2012-04-12 11:29:04 +01:00
|
|
|
class BuildListObserver < ActiveRecord::Observer
|
|
|
|
observe :build_list
|
|
|
|
|
|
|
|
def before_update(record)
|
|
|
|
if record.status_changed?
|
2013-01-24 11:32:00 +00:00
|
|
|
record.started_at = Time.now if record.status == BuildList::BUILD_STARTED
|
|
|
|
if [BuildList::BUILD_ERROR,
|
|
|
|
BuildList::SUCCESS,
|
2012-12-07 11:47:42 +00:00
|
|
|
BuildList::BUILD_CANCELING,
|
2013-02-06 13:14:59 +00:00
|
|
|
BuildList::TESTS_FAILED,
|
2012-12-07 11:47:42 +00:00
|
|
|
BuildList::BUILD_CANCELED].include? record.status
|
2012-04-12 11:29:04 +01:00
|
|
|
# stores time interval beetwin build start and finish in seconds
|
2012-12-07 11:47:42 +00:00
|
|
|
record.duration = record.current_duration if record.started_at
|
2012-06-15 17:05:55 +01:00
|
|
|
|
2013-01-24 11:32:00 +00:00
|
|
|
if record.status == BuildList::SUCCESS
|
2012-04-13 14:24:43 +01:00
|
|
|
# Update project average build time
|
2013-07-31 13:40:44 +01:00
|
|
|
begin
|
|
|
|
statistic = record.project.project_statistics.find_or_create_by_arch_id(record.arch_id)
|
|
|
|
rescue ActiveRecord::RecordNotUnique
|
|
|
|
retry
|
|
|
|
end
|
2014-02-25 22:27:29 +00:00
|
|
|
build_count = statistic.build_count.to_i
|
2014-02-25 22:40:48 +00:00
|
|
|
new_av_time = ( statistic.average_build_time * build_count + record.duration.to_i ) / ( build_count + 1 )
|
2014-01-21 04:51:49 +00:00
|
|
|
statistic.update_attributes(average_build_time: new_av_time, build_count: build_count + 1)
|
2012-06-15 17:05:55 +01:00
|
|
|
end
|
2012-04-12 11:29:04 +01:00
|
|
|
end
|
2012-09-17 16:18:02 +01:00
|
|
|
end
|
|
|
|
end # before_update
|
|
|
|
|
2012-04-12 11:29:04 +01:00
|
|
|
end
|