Skip to content

Commit

Permalink
Merge pull request #917 from openzim/artifacts_upload
Browse files Browse the repository at this point in the history
Artifacts upload
  • Loading branch information
benoit74 authored Feb 23, 2024
2 parents 08a1459 + bc23521 commit 3e5b6e6
Show file tree
Hide file tree
Showing 44 changed files with 582 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/QA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

- name: Install dependencies
run: |
pip install black==23.3.0 flake8==6.0.0 isort==5.12.0
pip install black==24.2.0 flake8==7.0.0 isort==5.13.2
black --version
flake8 --version
isort --version
Expand Down
16 changes: 10 additions & 6 deletions dispatcher/backend/maint-scripts/report_youtube_api_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ def report_youtube_api_keys(session: so.Session, *, display_unknown_secrets=Fals
if hashed_api_key not in schedules_by_api_key.keys():
schedules_by_api_key[hashed_api_key] = {
"api_key": api_key,
"key_name": known_api_keys[hashed_api_key]
if hashed_api_key in known_api_keys
else "unknown",
"key_name": (
known_api_keys[hashed_api_key]
if hashed_api_key in known_api_keys
else "unknown"
),
"schedules": [],
}
schedules_by_api_key[hashed_api_key]["schedules"].append(schedule.name)
Expand All @@ -69,9 +71,11 @@ def report_youtube_api_keys(session: so.Session, *, display_unknown_secrets=Fals
for hashed_api_key, data in schedules_by_api_key.items():
report_data["keys"].append(
{
"name": known_api_keys[hashed_api_key]
if hashed_api_key in known_api_keys.keys()
else "unknown",
"name": (
known_api_keys[hashed_api_key]
if hashed_api_key in known_api_keys.keys()
else "unknown"
),
"schedules": sorted(data["schedules"]),
}
)
Expand Down
8 changes: 8 additions & 0 deletions dispatcher/backend/src/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,24 @@
"ZIM_UPLOAD_URI", "sftp://[email protected]:1522/zim"
)
try:
# ZIM files expiration, 0 to disable expiration
ZIM_EXPIRATION = int(os.getenv("ZIM_EXPIRATION", "0"))
except Exception:
ZIM_EXPIRATION = 0
LOGS_UPLOAD_URI = os.getenv(
"LOGS_UPLOAD_URI", "sftp://[email protected]:1522/logs"
)
try:
# log files expiration, 0 to disable expiration
LOGS_EXPIRATION = int(os.getenv("LOGS_EXPIRATION", "30"))
except Exception:
LOGS_EXPIRATION = 30
ARTIFACTS_UPLOAD_URI = os.getenv("ARTIFACTS_UPLOAD_URI", None)
try:
# artifact files expiration, 0 to disable expiration
ARTIFACTS_EXPIRATION = int(os.getenv("ARTIFACTS_EXPIRATION", "30"))
except Exception:
ARTIFACTS_EXPIRATION = 30

# empty ZIMCHECK_OPTION means no zimcheck
ZIMCHECK_OPTION = os.getenv("ZIMCHECK_OPTION", "")
Expand Down
14 changes: 8 additions & 6 deletions dispatcher/backend/src/common/emailing.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ def send_email_via_mailgun(
url=f"{MAILGUN_API_URL}/messages",
auth=("api", MAILGUN_API_KEY),
data=data,
files=[
("attachment", (fpath.name, open(fpath, "rb").read()))
for fpath in attachments
]
if attachments
else [],
files=(
[
("attachment", (fpath.name, open(fpath, "rb").read()))
for fpath in attachments
]
if attachments
else []
),
timeout=REQ_TIMEOUT_NOTIFICATIONS,
)
resp.raise_for_status()
Expand Down
9 changes: 6 additions & 3 deletions dispatcher/backend/src/common/schemas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class ScheduleConfigSchema(SerializableSchema):
resources = fields.Nested(ResourcesSchema(), required=True)
flags = fields.Dict(required=True)
platform = String(required=True, allow_none=True, validate=validate_platform)
artifacts_globs = fields.List(String(validate=validate_not_empty), required=False)
monitor = fields.Boolean(required=True, truthy=[True], falsy=[False])

@staticmethod
Expand All @@ -86,9 +87,11 @@ def get_offliner_schema(offliner):
Offliner.nautilus: NautilusFlagsSchema,
Offliner.ted: TedFlagsSchema,
Offliner.openedx: OpenedxFlagsSchema,
Offliner.zimit: ZimitFlagsSchemaRelaxed
if constants.ZIMIT_USE_RELAXED_SCHEMA
else ZimitFlagsSchema,
Offliner.zimit: (
ZimitFlagsSchemaRelaxed
if constants.ZIMIT_USE_RELAXED_SCHEMA
else ZimitFlagsSchema
),
Offliner.kolibri: KolibriFlagsSchema,
Offliner.wikihow: WikihowFlagsSchema,
Offliner.ifixit: IFixitFlagsSchema,
Expand Down
6 changes: 3 additions & 3 deletions dispatcher/backend/src/common/schemas/orms.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ def get_duration(schedule: dbm.Schedule):
duration_res["default"] = ScheduleFullSchema.get_one_duration(duration)
if duration.worker:
duration_res["available"] = True
duration_res["workers"][
duration.worker.name
] = ScheduleFullSchema.get_one_duration(duration)
duration_res["workers"][duration.worker.name] = (
ScheduleFullSchema.get_one_duration(duration)
)
return duration_res

def get_is_requested(schedule: dbm.Schedule):
Expand Down
3 changes: 3 additions & 0 deletions dispatcher/backend/src/common/schemas/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ class UpdateSchema(Schema):
resources = fields.Nested(ResourcesSchema, required=False)
monitor = fields.Boolean(required=False, truthy={True}, falsy={False})
flags = fields.Dict(required=False)
artifacts_globs = fields.List(
String(validate=validate_not_empty), required=False, allow_none=True
)


# schedule clone
Expand Down
18 changes: 14 additions & 4 deletions dispatcher/backend/src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def add_to_debug_if_present(
task=task, kwargs_key="timeout", container_key="timeout"
)
add_to_container_if_present(task=task, kwargs_key="log", container_key="log")
add_to_container_if_present(
task=task, kwargs_key="artifacts", container_key="artifacts"
)
add_to_debug_if_present(task=task, kwargs_key="task_log", debug_key="log")
add_to_debug_if_present(task=task, kwargs_key="task_name", debug_key="task_name")
add_to_debug_if_present(task=task, kwargs_key="task_args", debug_key="task_args")
Expand Down Expand Up @@ -348,10 +351,17 @@ def task_checked_file_event_handler(session: so.Session, task_id: UUID, payload:

def task_update_event_handler(session: so.Session, task_id: UUID, payload: dict):
timestamp = get_timestamp_from_event(payload)
log = payload.get("log") # filename / S3 key of text file at upload_uri[logs]
logger.info(f"Task update: {task_id}, log: {log}")

save_event(session, task_id, TaskStatus.update, timestamp, log=log)
if "log" in payload:
log = payload.get("log") # filename / S3 key of text file at upload_uri[logs]
logger.info(f"Task update: {task_id}, log: {log}")
save_event(session, task_id, TaskStatus.update, timestamp, log=log)

if "artifacts" in payload:
artifacts = payload.get(
"artifacts"
) # filename / S3 key of text file at upload_uri[logs]
logger.info(f"Task update: {task_id}, artifacts: {artifacts}")
save_event(session, task_id, TaskStatus.update, timestamp, artifacts=artifacts)


def handle_others(task_id: UUID, event: str, payload: dict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-05-04 12:36:14.802432
"""

from alembic import op

# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-04-26 12:21:57.205579
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-05-18 13:35:13.362937
"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-09-26 07:56:45.008277
"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-04-06 05:13:40.448095
"""

from alembic import op

# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-05-12 15:29:06.706797
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-05-18 10:53:05.286686
"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-05-04 11:27:30.248671
"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-04-13 10:10:52.820099
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-04-06 15:56:02.435956
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-04-28 11:29:30.878410
"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-04-03 18:01:18.286681
"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-09-29 10:59:39.739351
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-04-06 04:57:11.449333
"""

from alembic import op

# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-03-31 14:03:52.822993
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-05-04 14:08:19.014269
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-03-31 18:05:44.896451
"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-04-03 21:12:33.745734
"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql
Expand Down
Empty file.
Loading

0 comments on commit 3e5b6e6

Please sign in to comment.