mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-11-02 19:02:31 +00:00
feat(oci): support custom Compose workers and migration jobs
This commit is contained in:
@@ -15,6 +15,7 @@ import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import uuid
|
||||
|
||||
from oci_installation_state import command, image_from_archive, private_directory, sha
|
||||
@@ -42,8 +43,22 @@ def location(root, vmid):
|
||||
return path / 'oci-compose.json'
|
||||
|
||||
|
||||
def _acquire_lock(fd, timeout):
|
||||
"""Wait only for acquisition; a failure inside the operation is never replayed."""
|
||||
deadline = time.monotonic() + max(0, float(timeout))
|
||||
while True:
|
||||
try:
|
||||
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
return
|
||||
except BlockingIOError:
|
||||
remaining = deadline - time.monotonic()
|
||||
if remaining <= 0:
|
||||
raise
|
||||
time.sleep(min(0.2, remaining))
|
||||
|
||||
|
||||
@contextmanager
|
||||
def locked(root):
|
||||
def locked(root, timeout=0):
|
||||
private_directory(root)
|
||||
path = root / '.lock'
|
||||
if path.is_symlink():
|
||||
@@ -53,12 +68,12 @@ def locked(root):
|
||||
fd = int(inherited)
|
||||
if os.fstat(fd).st_ino != path.stat().st_ino or os.fstat(fd).st_dev != path.stat().st_dev:
|
||||
raise ValueError(translate('Wrong inherited registry lock'))
|
||||
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
_acquire_lock(fd, timeout)
|
||||
yield
|
||||
else:
|
||||
with path.open('a') as lock:
|
||||
os.chmod(path, 0o600)
|
||||
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
_acquire_lock(lock, timeout)
|
||||
yield
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user