Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Commit

Permalink
Wrap .get_feature_user in a retry-able transaction
Browse files Browse the repository at this point in the history
dazoakley committed Jan 27, 2015
1 parent 56db319 commit 995c3c1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/bandiera/feature_service.rb
Original file line number Diff line number Diff line change
@@ -78,8 +78,9 @@ def update_feature(group, name, params)
# FeatureUsers

def get_feature_user(feature, user_id)
conditions = { feature_id: feature.id, user_id: user_id }
FeatureUser.first(conditions) || FeatureUser.create(conditions)
db.transaction(retry_on: [Sequel::UniqueConstraintViolation, Sequel::SerializationFailure]) do
FeatureUser.find_or_create(feature_id: feature.id, user_id: user_id)
end
end

private

0 comments on commit 995c3c1

Please sign in to comment.