#245: rescue RecordNotUnique error

This commit is contained in:
Vokhmin Alexey V 2013-07-31 16:40:44 +04:00
parent e38bfa797f
commit 5a660ded4e
1 changed files with 5 additions and 1 deletions

View File

@ -14,7 +14,11 @@ class BuildListObserver < ActiveRecord::Observer
if record.status == BuildList::SUCCESS if record.status == BuildList::SUCCESS
# Update project average build time # Update project average build time
begin
statistic = record.project.project_statistics.find_or_create_by_arch_id(record.arch_id) statistic = record.project.project_statistics.find_or_create_by_arch_id(record.arch_id)
rescue ActiveRecord::RecordNotUnique
retry
end
build_count = statistic.build_count build_count = statistic.build_count
new_av_time = ( statistic.average_build_time * build_count + record.duration ) / ( build_count + 1 ) new_av_time = ( statistic.average_build_time * build_count + record.duration ) / ( build_count + 1 )
statistic.update_attributes(:average_build_time => new_av_time, :build_count => build_count) statistic.update_attributes(:average_build_time => new_av_time, :build_count => build_count)