add lock to prevent multiple workers from accessing repo db
This commit is contained in:
@@ -11,7 +11,7 @@ import signal
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from multiprocessing import Pool, Queue, current_process
|
from multiprocessing import Pool, Queue, current_process, Lock
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from packaging import version
|
from packaging import version
|
||||||
@@ -22,6 +22,7 @@ regex_march = re.compile(r"(-march=)(.+?) ", re.MULTILINE)
|
|||||||
regex_validkeys = re.compile(r"^validpgpkeys\+?=\((.*?)\)", re.MULTILINE | re.DOTALL)
|
regex_validkeys = re.compile(r"^validpgpkeys\+?=\((.*?)\)", re.MULTILINE | re.DOTALL)
|
||||||
fp = None
|
fp = None
|
||||||
update_last = time.time()
|
update_last = time.time()
|
||||||
|
repo_lock = Lock()
|
||||||
|
|
||||||
|
|
||||||
def build(pkgbuild, repo):
|
def build(pkgbuild, repo):
|
||||||
@@ -81,6 +82,7 @@ def build(pkgbuild, repo):
|
|||||||
shutil.copy2(pkg, os.path.join(config["basedir"]["repo"], repo, "os", config["arch"] + "/"))
|
shutil.copy2(pkg, os.path.join(config["basedir"]["repo"], repo, "os", config["arch"] + "/"))
|
||||||
|
|
||||||
# repo
|
# repo
|
||||||
|
repo_lock.acquire()
|
||||||
r_res = subprocess.run(["repo-add", "-s", "-v",
|
r_res = subprocess.run(["repo-add", "-s", "-v",
|
||||||
os.path.join(config["basedir"]["repo"], repo, "os", config["arch"],
|
os.path.join(config["basedir"]["repo"], repo, "os", config["arch"],
|
||||||
repo + ".db.tar.xz"),
|
repo + ".db.tar.xz"),
|
||||||
@@ -88,6 +90,7 @@ def build(pkgbuild, repo):
|
|||||||
logging.debug("[REPO-ADD] %s", r_res.stdout.decode())
|
logging.debug("[REPO-ADD] %s", r_res.stdout.decode())
|
||||||
if r_res.returncode:
|
if r_res.returncode:
|
||||||
logging.error("[%s/%s] Repo action failed: %s", repo, name, r_res.stdout.decode())
|
logging.error("[%s/%s] Repo action failed: %s", repo, name, r_res.stdout.decode())
|
||||||
|
repo_lock.release()
|
||||||
build_cleanup()
|
build_cleanup()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -95,6 +98,7 @@ def build(pkgbuild, repo):
|
|||||||
["paccache", "-rc", os.path.join(config["basedir"]["repo"], repo, "os", config["arch"]), "-k", "1"],
|
["paccache", "-rc", os.path.join(config["basedir"]["repo"], repo, "os", config["arch"]), "-k", "1"],
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
logging.debug("[PACCACHE] %s", p_res.stdout.decode())
|
logging.debug("[PACCACHE] %s", p_res.stdout.decode())
|
||||||
|
repo_lock.release()
|
||||||
if p_res.returncode:
|
if p_res.returncode:
|
||||||
logging.error("[%s/%s] Repo cleanup failed: %s", repo, name, p_res.stdout.decode())
|
logging.error("[%s/%s] Repo cleanup failed: %s", repo, name, p_res.stdout.decode())
|
||||||
build_cleanup()
|
build_cleanup()
|
||||||
@@ -102,7 +106,7 @@ def build(pkgbuild, repo):
|
|||||||
|
|
||||||
# cleanup
|
# cleanup
|
||||||
build_cleanup()
|
build_cleanup()
|
||||||
logging.info("[%s/%s] Build successful (%s)", repo, name, int(time.time() - start_time))
|
logging.info("[%s/%s] Build successful (%ss)", repo, name, int(time.time() - start_time))
|
||||||
|
|
||||||
|
|
||||||
def run_worker() -> None:
|
def run_worker() -> None:
|
||||||
|
Reference in New Issue
Block a user