Skip to content

Commit

Permalink
fixup! fixup! Add loop functionality to service
Browse files Browse the repository at this point in the history
  • Loading branch information
waterflow80 committed Dec 9, 2024
1 parent 1b7cd07 commit 83bb4bd
Showing 1 changed file with 37 additions and 30 deletions.
67 changes: 37 additions & 30 deletions python/lzreposync/src/lzreposync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,28 @@ def _add_content_source(channel_label, source_url, source_label, source_type="yu
def _sync_channel(channel_label, cache_dir, batch_size=20, no_errata=False):
"""
Synchronize the repositories of the given channel
:return: A tuple that contains the success status and another return object (error message or a list of failed repos)
"""
channel = get_channel_info_by_label(channel_label)
channel_arch = channel["arch"].split("-")[
channel_arch = channel["arch"].split("-", 1)[
1
] # Initially the value is like: 'channel-x86_64'
if not channel:
logging.error("Couldn't fetch channel with label %s", channel_label)
return -1
return False, f"No channel with found with label {channel_label}"
compatible_arches = get_compatible_arches(channel_label)
if channel_arch and channel_arch != ".*" and channel_arch not in compatible_arches:
logging.error(
"Not compatible arch: %s for channel: %s",
channel_arch,
channel_label,
)
return -1
return False, f"Arch {channel_arch} is not compatible with {channel_label}"
try:
target_repos = db_utils.get_repositories_by_channel_label(channel_label)
except NoSourceFoundForChannel as e:
print("Error:", e.msg)
return -1
return False, f"No source found for channel {channel_label}"

failed_repos = [] # contains the list of labels of failed repos
for repo in target_repos:
Expand All @@ -102,35 +103,36 @@ def _sync_channel(channel_label, cache_dir, batch_size=20, no_errata=False):
failed_repos.append(repo.repo_label)

elif repo.repo_type == "deb":
dep_repo = DebRepo(
repo.source_url,
cache_dir,
pkg_dir="/tmp",
channel_label=repo.channel_label,
)
try:
dep_repo = DebRepo(
repo.source_url,
cache_dir,
pkg_dir="/tmp",
channel_label=repo.channel_label,
)
dep_repo.verify()

logging.debug("Importing package for repo %s", repo.repo_label)
failed = import_repository_packages_in_batch(
dep_repo,
batch_size,
channel,
compatible_arches=compatible_arches,
)
logging.debug(
"Completed import for repo %s with %d failed packages",
repo.repo_label,
failed,
)
except GeneralRepoException as e:
logging.error("__init__.py: Couldn't verify signature ! %s", e)
failed_repos.append(repo.repo_label)

logging.debug("Importing package for repo %s", repo.repo_label)
failed = import_repository_packages_in_batch(
dep_repo,
batch_size,
channel,
compatible_arches=compatible_arches,
)
logging.debug(
"Completed import for repo %s with %d failed packages",
repo.repo_label,
failed,
)
else:
# TODO: handle repositories other than yum and deb
logging.debug("Not supported repo type: %s", repo.repo_type)
continue
return failed_repos
return True, failed_repos


def _display_failed_repos(repos):
Expand All @@ -141,6 +143,7 @@ def _display_failed_repos(repos):
print(f"=> Failed syncing repository: {repo_label}")


# TODO: [Whole file] Make better logging using the right log functions
def main():
parser = argparse.ArgumentParser(
description="Lazy reposync service",
Expand Down Expand Up @@ -317,26 +320,30 @@ def main():
print(f"INFO: Start synchronizing channel: {ch_label}")
# Update the channel status to 'in_progress'
update_channel_status(ch_label, "in_progress")
ret = _sync_channel(
success, res = _sync_channel(
ch_label, args.cache, args.batch_size, args.no_errata
)
if isinstance(ret, int):
if not success:
channel["status"] = "failed"
update_channel_status(ch_label, "failed")
print(f"Failed synchronizing channel {ch_label}")
elif isinstance(ret, list):
if len(ret) == 0:
print(
f"Failed synchronizing channel {ch_label}. Error: {res}"
)
else:
if len(res) == 0:
# No failed repositories
update_channel_status(ch_label, "done")
print(f"Successfully synchronized channel {ch_label}")
else:
update_channel_status(ch_label, "failed")
print(
f"Failed fully synchronizing channel {ch_label}. Some repos might have been synced."
f"Failed fully synchronizing channel {ch_label}. Finished with {len(res)} failed repos"
)
_display_failed_repos(ret)
_display_failed_repos(res)
sleep(SLEEP_TIME)
except KeyboardInterrupt:
print("Lzreposync is being stopped..")
# TODO: we might want to add some cleanup
# TODO: We should update the status of the channel before leaving, not leaving it in a blocking status
# like 'in_progress'
exit(0)

0 comments on commit 83bb4bd

Please sign in to comment.