rosa-build/app/models/build_list_observer.rb

25 lines
979 B
Ruby
Raw Normal View History

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,
BuildList::BUILD_CANCELING,
BuildList::BUILD_CANCELED].include? record.status
2012-04-12 11:29:04 +01:00
# stores time interval beetwin build start and finish in seconds
record.duration = record.current_duration if record.started_at
2013-01-24 11:32:00 +00:00
if record.status == BuildList::SUCCESS
# Update project average build time
build_count = record.project.build_count
new_av_time = ( record.project.average_build_time * build_count + record.duration ) / ( build_count + 1 )
record.project.update_attributes({ :average_build_time => new_av_time, :build_count => build_count + 1 }, :without_protection => true)
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