Lock import resources on updates to prevent write collisions.
This commit is contained in:
parent
3c50f366f7
commit
d214106f98
1 changed files with 24 additions and 20 deletions
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue