Skip to content

Commit

Permalink
Merge pull request #31 from kiwix/log-cli-actions
Browse files Browse the repository at this point in the history
log cli actions
  • Loading branch information
elfkuzco authored Aug 4, 2024
2 parents 45a8704 + c81a437 commit 2ab87d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 0 additions & 3 deletions backend/src/mirrors_qa_backend/cli/worker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pycountry
from cryptography.hazmat.primitives import serialization

from mirrors_qa_backend import logger
from mirrors_qa_backend.db import Session
from mirrors_qa_backend.db.country import update_countries as update_db_countries
from mirrors_qa_backend.db.worker import create_worker as create_db_worker
Expand Down Expand Up @@ -51,8 +50,6 @@ def create_worker(
public_key, # pyright: ignore [reportGeneralTypeIssues, reportArgumentType]
)

logger.info(f"Created worker {worker_id} successfully")


def update_worker(worker_id: str, country_codes: list[str]):
"""Update worker's data.
Expand Down
7 changes: 7 additions & 0 deletions backend/src/mirrors_qa_backend/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,22 @@ def main():

if args.cli_name == UPDATE_MIRRORS_CLI:
try:
logger.debug("Updating list of mirrors...")
update_mirrors()
except Exception as exc:
logger.error(f"error while updating mirrors: {exc!s}")
sys.exit(1)
logger.info("Updated list of mirrors on database.")
elif args.cli_name == SCHEDULER_CLI:
logger.debug("Starting scheduler task...")
start_scheduler(
args.scheduler_sleep_seconds,
args.expire_tests_since,
args.workers_since,
)
elif args.cli_name == CREATE_WORKER_CLI:
try:
logger.debug(f"Creating worker {args.worker_id!r}...")
create_worker(
args.worker_id,
bytes(args.public_key_file.read(), encoding="ascii"),
Expand All @@ -121,15 +125,18 @@ def main():
except Exception as exc:
logger.error(f"error while creating worker: {exc!s}")
sys.exit(1)
logger.info(f"Saved worker {args.worker_id!r} to database.")
elif args.cli_name == UPDATE_WORKER_CLI:
try:
logger.debug(f"Updating list of mirrors for {args.worker_id!r}")
update_worker(
args.worker_id,
args.countries if args.countries else [],
)
except Exception as exc:
logger.error(f"error while updating worker: {exc!s}")
sys.exit(1)
logger.info(f"Updated countries for worker {args.worker_id!r}")
else:
args.print_help()

Expand Down

0 comments on commit 2ab87d4

Please sign in to comment.