Skip to content

Commit eb9b112

Browse files
committed
Handle unsupported jobs gracefully, bump bma-client-lib dep to 0.7.0
1 parent c8573e5 commit eb9b112

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ classifiers = [
1313
]
1414
dependencies = [
1515
"typer-slim==0.12.5",
16-
"bma-client-lib>=0.6.0",
16+
"bma-client-lib>=0.7.0",
1717
]
1818
name = "bma-cli"
1919
description = "BornHack Media Archive CLI Tool"

src/bma_cli/bma_cli.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import click
1111
import typer
1212
from bma_client_lib import BmaClient
13-
from bma_client_lib.datastructures import job_types
13+
from bma_client_lib.datastructures import JobNotSupportedError, job_types
1414

1515
APP_NAME = "bma-cli"
1616
app = typer.Typer()
@@ -66,12 +66,20 @@ def download(file_uuid: uuid.UUID) -> None:
6666
def grind() -> None:
6767
"""Get jobs from the server and handle them."""
6868
client, config = init()
69+
# keep track of failing jobs to prevent getting them assigned again
70+
failed_jobs: set[str] = set()
71+
# run in a loop to make sure jobs created as a result of other jobs being completed are all processed
6972
while True:
7073
# first get any unfinished jobs already assigned to this client
71-
jobs = client.get_jobs(job_filter=f"?limit=0&finished=false&client_uuid={client.uuid}")
74+
job_filter = f"?limit=0&finished=false&client_uuid={client.uuid}"
75+
if failed_jobs:
76+
job_filter += f"&skip_jobs={','.join(failed_jobs)}"
77+
jobs = client.get_jobs(job_filter=job_filter)
7278
if not jobs:
73-
# no unfinished jobs assigned to this client, ask for new assignment
74-
jobs = client.get_job_assignment()
79+
# no unfinished jobs assigned to this client, ask for new assignment,
80+
# but skip jobs which previously failed
81+
job_filter = f"?skip_jobs={','.join(failed_jobs)}" if failed_jobs else ""
82+
jobs = client.get_job_assignment(job_filter=job_filter)
7583

7684
if not jobs:
7785
click.echo("Nothing left to do.")
@@ -82,7 +90,13 @@ def grind() -> None:
8290
for dictjob in jobs:
8391
job = job_types[dictjob["job_type"]](**dictjob)
8492
click.echo(f"Handling {job.job_type} {job.job_uuid} ...")
85-
client.handle_job(job=job)
93+
try:
94+
client.handle_job(job=job)
95+
except JobNotSupportedError:
96+
logger.exception(f"Job {job.job_uuid} not supported")
97+
failed_jobs.add(str(job.job_uuid))
98+
client.unassign_job(job=job)
99+
continue
86100
click.echo("Done grinding for now!")
87101

88102

0 commit comments

Comments
 (0)