From 5a660ded4e5b146d1064050aff62270a27ba741a Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 31 Jul 2013 16:40:44 +0400 Subject: [PATCH] #245: rescue RecordNotUnique error --- app/models/build_list_observer.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/build_list_observer.rb b/app/models/build_list_observer.rb index 02ffe37e6..89ab77267 100644 --- a/app/models/build_list_observer.rb +++ b/app/models/build_list_observer.rb @@ -14,7 +14,11 @@ class BuildListObserver < ActiveRecord::Observer if record.status == BuildList::SUCCESS # Update project average build time - statistic = record.project.project_statistics.find_or_create_by_arch_id(record.arch_id) + begin + statistic = record.project.project_statistics.find_or_create_by_arch_id(record.arch_id) + rescue ActiveRecord::RecordNotUnique + retry + end build_count = statistic.build_count 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)