mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 20:05:55 +08:00
Change/fix asset locking mechanism
Close SCI-3870
This commit is contained in:
parent
37abc992f7
commit
5cb900370a
1 changed files with 2 additions and 3 deletions
|
@ -449,19 +449,18 @@ class Asset < ApplicationRecord
|
||||||
# locked?, lock_asset and refresh_lock rely on the asset
|
# locked?, lock_asset and refresh_lock rely on the asset
|
||||||
# being locked in the database to prevent race conditions
|
# being locked in the database to prevent race conditions
|
||||||
def locked?
|
def locked?
|
||||||
|
unlock_expired
|
||||||
!lock.nil?
|
!lock.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def lock_asset(lock_string)
|
def lock_asset(lock_string)
|
||||||
self.lock = lock_string
|
self.lock = lock_string
|
||||||
self.lock_ttl = Time.now.to_i + LOCK_DURATION
|
self.lock_ttl = Time.now.to_i + LOCK_DURATION
|
||||||
delay(queue: :assets, run_at: LOCK_DURATION.seconds.from_now).unlock_expired
|
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
def refresh_lock
|
def refresh_lock
|
||||||
self.lock_ttl = Time.now.to_i + LOCK_DURATION
|
self.lock_ttl = Time.now.to_i + LOCK_DURATION
|
||||||
delay(queue: :assets, run_at: LOCK_DURATION.seconds.from_now).unlock_expired
|
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -473,7 +472,7 @@ class Asset < ApplicationRecord
|
||||||
|
|
||||||
def unlock_expired
|
def unlock_expired
|
||||||
with_lock do
|
with_lock do
|
||||||
if !lock_ttl.nil? && lock_ttl >= Time.now.to_i
|
if !lock_ttl.nil? && lock_ttl <= Time.now.to_i
|
||||||
self.lock = nil
|
self.lock = nil
|
||||||
self.lock_ttl = nil
|
self.lock_ttl = nil
|
||||||
save!
|
save!
|
||||||
|
|
Loading…
Add table
Reference in a new issue