Skip to content

Commit

Permalink
Make sure process_incoming is serialized
Browse files Browse the repository at this point in the history
`inoticoming` will happily call `process_incoming` concurrently, so make
sure we're properly locking the repos to avoid corruption.
  • Loading branch information
elprans committed Sep 12, 2023
1 parent 0d9c2a4 commit 7b5c5a5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
67 changes: 37 additions & 30 deletions server/process_incoming.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import boto3
import click
import filelock
import semver
import tomli

Expand Down Expand Up @@ -543,36 +544,42 @@ def main(
metadata = json.loads(metadata_file.read())
repository = metadata.get("repository")

if repository == "generic":
process_generic(
cfg,
s3,
tf,
metadata,
bucket,
pathlib.Path(temp_dir),
pathlib.Path(local_dir),
)
elif repository == "apt":
process_apt(
cfg,
s3,
tf,
metadata,
bucket,
pathlib.Path(temp_dir),
pathlib.Path(local_dir),
)
elif repository == "rpm":
process_rpm(
cfg,
s3,
tf,
metadata,
bucket,
pathlib.Path(temp_dir),
pathlib.Path(local_dir),
)
local_dir_path = pathlib.Path(local_dir)
temp_dir_path = pathlib.Path(temp_dir)
lock_path = local_dir_path / f"{repository}.lock"

print(f"Obtaining {lock_path}")
with filelock.FileLock(lock_path, timeout=3600):
if repository == "generic":
process_generic(
cfg,
s3,
tf,
metadata,
bucket,
temp_dir_path,
local_dir_path,
)
elif repository == "apt":
process_apt(
cfg,
s3,
tf,
metadata,
bucket,
temp_dir_path,
local_dir_path,
)
elif repository == "rpm":
process_rpm(
cfg,
s3,
tf,
metadata,
bucket,
temp_dir_path,
local_dir_path,
)

print("Successfully processed", path)
finally:
Expand Down
1 change: 1 addition & 0 deletions server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies = [
'typing-extensions',
'tomli',
'semver',
'filelock',
]

[project.urls]
Expand Down

0 comments on commit 7b5c5a5

Please sign in to comment.