-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from kiwix/worker-manger
Set up worker manager to run tasks in containers
- Loading branch information
Showing
53 changed files
with
1,656 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Worker Manager QA | ||
|
||
on: | ||
pull_request: | ||
push: | ||
paths: | ||
- 'worker/manager/**' | ||
branches: | ||
- main | ||
|
||
jobs: | ||
|
||
check-qa: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version-file: worker/manager/pyproject.toml | ||
architecture: x64 | ||
|
||
- name: Install dependencies (and project) | ||
working-directory: worker/manager | ||
run: | | ||
pip install -U pip | ||
pip install -e .[lint,scripts,test,check] | ||
- name: Check black formatting | ||
working-directory: worker/manager | ||
run: inv lint-black | ||
|
||
- name: Check ruff | ||
working-directory: worker/manager | ||
run: inv lint-ruff | ||
|
||
- name: Check pyright | ||
working-directory: worker/manager | ||
run: inv check-pyright |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Publish worker-task Docker image | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'worker/task/**' | ||
branches: | ||
- main | ||
|
||
jobs: | ||
|
||
publish-worker-task: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Retrieve source code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Build and publish Docker Image | ||
uses: openzim/docker-publish-action@v10 | ||
with: | ||
image-name: kiwix/mirrors-qa-task-worker | ||
latest-on-tag: true | ||
tag-pattern: /^v([0-9.]+)$/ | ||
restrict-to: kiwix/mirrors-qa | ||
context: worker/task | ||
registries: ghcr.io | ||
credentials: | ||
GHCRIO_USERNAME=${{ secrets.GHCR_USERNAME }} | ||
GHCRIO_TOKEN=${{ secrets.GHCR_TOKEN }} | ||
repo_description: auto | ||
repo_overview: auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# mirrors-qa | ||
|
||
Q/A tools for Kiwix Download Mirrors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import sys | ||
|
||
from mirrors_qa_backend import logger | ||
from mirrors_qa_backend.db import Session | ||
from mirrors_qa_backend.db.mirrors import create_or_update_mirror_status | ||
from mirrors_qa_backend.exceptions import MirrorsRequestError | ||
from mirrors_qa_backend.extract import get_current_mirrors | ||
|
||
|
||
def update_mirrors() -> None: | ||
logger.info("Updating mirrors list.") | ||
try: | ||
with Session.begin() as session: | ||
results = create_or_update_mirror_status(session, get_current_mirrors()) | ||
except MirrorsRequestError as exc: | ||
logger.info(f"error while updating mirrors: {exc}") | ||
sys.exit(1) | ||
logger.info( | ||
f"Updated mirrors list. Added {results.nb_mirrors_added} mirror(s), " | ||
f"disabled {results.nb_mirrors_disabled} mirror(s)" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import sys | ||
|
||
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.worker import create_worker as create_db_worker | ||
|
||
|
||
def create_worker(worker_id: str, private_key_data: bytes, country_codes: list[str]): | ||
# Ensure all the countries are valid country codes | ||
for country_code in country_codes: | ||
if len(country_code) != 2: # noqa: PLR2004 | ||
logger.info(f"Country code '{country_code}' must be two characters long") | ||
sys.exit(1) | ||
|
||
if not pycountry.countries.get(alpha_2=country_code): | ||
logger.info(f"'{country_code}' is not valid country code") | ||
sys.exit(1) | ||
|
||
try: | ||
private_key = serialization.load_pem_private_key( | ||
private_key_data, password=None | ||
) # pyright: ignore[reportReturnType] | ||
except Exception as exc: | ||
logger.info(f"Unable to load private key: {exc}") | ||
sys.exit(1) | ||
|
||
try: | ||
with Session.begin() as session: | ||
create_db_worker( | ||
session, | ||
worker_id, | ||
country_codes, | ||
private_key, # pyright: ignore [reportGeneralTypeIssues, reportArgumentType] | ||
) | ||
except Exception as exc: | ||
logger.info(f"error while creating worker: {exc}") | ||
sys.exit(1) | ||
|
||
logger.info(f"Created worker {worker_id} successfully") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.