Lock import resources on updates to prevent write collisions.

This commit is contained in:
Thorsten Eckel 2017-06-27 16:48:44 +02:00
parent 3c50f366f7
commit d214106f98

View file

@ -91,6 +91,9 @@ module Import
@resource = lookup_existing(resource, *args) @resource = lookup_existing(resource, *args)
return false if !@resource return false if !@resource
# lock the current resource for write access
@resource.with_lock do
# delete since we have an update and # delete since we have an update and
# the record is already created # the record is already created
resource.delete(:created_by_id) resource.delete(:created_by_id)
@ -117,6 +120,7 @@ module Import
@resource.save! @resource.save!
true true
end end
end
def lookup_existing(resource, *_args) def lookup_existing(resource, *_args)