Commit c17cc2de authored by Alex Kalderimis's avatar Alex Kalderimis

Rename lock method for DesignManagement::Version

It is now named `with_lock`, and its use is described in the comment on
`.create_for_designs`.
parent c56eca3f
...@@ -66,6 +66,10 @@ module DesignManagement ...@@ -66,6 +66,10 @@ module DesignManagement
# designs, and not being able to add designs without a saved version. Also this # designs, and not being able to add designs without a saved version. Also this
# method inserts designs in bulk, rather than one by one. # method inserts designs in bulk, rather than one by one.
# #
# Before calling this method, callers must guard against concurrent
# modification by obtaining the lock on the design repository. See:
# `DesignManagement::Version.with_lock`.
#
# Parameters: # Parameters:
# - design_actions [DesignManagement::DesignAction]: # - design_actions [DesignManagement::DesignAction]:
# the actions that have been performed in the repository. # the actions that have been performed in the repository.
...@@ -98,8 +102,8 @@ module DesignManagement ...@@ -98,8 +102,8 @@ module DesignManagement
CREATION_TTL = 5.seconds CREATION_TTL = 5.seconds
RETRY_DELAY = ->(num) { 0.2.seconds * num**2 } RETRY_DELAY = ->(num) { 0.2.seconds * num**2 }
def self.lock_for_creation(project_id, repository, &block) def self.with_lock(project_id, repository, &block)
key = "lock_for_creation:#{name}:{#{project_id}}" key = "with_lock:#{name}:{#{project_id}}"
in_lock(key, ttl: CREATION_TTL, retries: 5, sleep_sec: RETRY_DELAY) do |_retried| in_lock(key, ttl: CREATION_TTL, retries: 5, sleep_sec: RETRY_DELAY) do |_retried|
repository.create_if_not_exists repository.create_if_not_exists
......
...@@ -37,7 +37,7 @@ module DesignManagement ...@@ -37,7 +37,7 @@ module DesignManagement
attr_reader :designs attr_reader :designs
def delete_designs! def delete_designs!
DesignManagement::Version.lock_for_creation(project.id, repository) do DesignManagement::Version.with_lock(project.id, repository) do
run_actions(build_actions) run_actions(build_actions)
end end
end end
......
...@@ -33,7 +33,7 @@ module DesignManagement ...@@ -33,7 +33,7 @@ module DesignManagement
attr_reader :files attr_reader :files
def upload_designs! def upload_designs!
::DesignManagement::Version.lock_for_creation(project.id, repository) do ::DesignManagement::Version.with_lock(project.id, repository) do
actions = build_actions actions = build_actions
[actions.map(&:design), actions.presence && run_actions(actions)] [actions.map(&:design), actions.presence && run_actions(actions)]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment