Simplify database locking
Use a single lock for everything to ensure we don’t go inconsistent. One exception is the firewall nodes table which is only accessed when pushing updated config.
This commit is contained in:
parent
93458c4782
commit
22cec64bef
5 changed files with 19 additions and 18 deletions
|
@ -13,12 +13,12 @@ def lock(name, timeout=5):
|
|||
time.sleep(1)
|
||||
raise TimeoutError(f'could not lock {name}')
|
||||
|
||||
def unlock(name):
|
||||
def unlock(name='db'):
|
||||
lockfile = pathlib.Path.home() / f'{name}.lock'
|
||||
lockfile.unlink(missing_ok=True)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def locked(name):
|
||||
def locked(name='db'):
|
||||
lock(name)
|
||||
try:
|
||||
yield name
|
||||
|
@ -36,9 +36,9 @@ def write(name, data):
|
|||
f.close()
|
||||
|
||||
def load(name):
|
||||
with locked(name):
|
||||
with locked():
|
||||
return read(name)
|
||||
|
||||
def save(name, data):
|
||||
with locked(name):
|
||||
with locked():
|
||||
write(name, data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue