Skip to content

Commit

Permalink
Mark status of task as ERROR when worker fails
Browse files Browse the repository at this point in the history
  • Loading branch information
greenw0lf committed Oct 10, 2024
1 parent 392e89d commit b8f254c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import time
import tomli
from typing import Optional

from base_util import (
get_asset_info,
Expand Down Expand Up @@ -37,7 +38,7 @@ def _get_project_meta():
version = str(pkg_meta["version"])


def run(input_uri: str, output_uri: str, model=None) -> bool:
def run(input_uri: str, output_uri: str, model=None) -> Optional[str]:
logger.info(f"Processing {input_uri} (save to --> {output_uri})")
start_time = time.time()
prov_steps = [] # track provenance
Expand All @@ -46,7 +47,7 @@ def run(input_uri: str, output_uri: str, model=None) -> bool:
logger.info(result)
if not result:
logger.error("Could not obtain input, quitting...")
return False
return "Input download failed"

prov_steps.append(result.provenance)

Expand All @@ -58,7 +59,7 @@ def run(input_uri: str, output_uri: str, model=None) -> bool:
transcode_output = try_transcode(input_path, asset_id, extension)
if not transcode_output:
logger.error("The transcode failed to yield a valid file to continue with")
return False
return "Transcode failed"
else:
input_path = transcode_output.transcoded_file_path
prov_steps.append(transcode_output.provenance)
Expand Down Expand Up @@ -137,7 +138,7 @@ def run(input_uri: str, output_uri: str, model=None) -> bool:
else:
logger.info("No output_uri specified, so all is done")

return True
return None


# if S3 output_uri is supplied transfers data to S3 location
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ services:
- ./model:/model
- ./data:/data
container_name: whisper-asr-worker
# args: ["--output-uri"]
env_file:
- .env.override
logging:
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def run_job(input_uri: str, output_uri: str):
logger.error("Please supply the --input and --output params")
return False

return asr.run(input_uri, output_uri)
asr.run(input_uri, output_uri)


# Start the worker
Expand Down
6 changes: 4 additions & 2 deletions whisper_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Task(BaseModel):
output_uri: str
status: Status = Status.CREATED
id: str | None = None
error_msg: str | None = None


all_tasks = [
Expand Down Expand Up @@ -91,8 +92,9 @@ def try_whisper(task: Task):
try:
task.status = Status.PROCESSING
update_task(task)
run(task.input_uri, task.output_uri, model)
task.status = Status.DONE
error_msg = run(task.input_uri, task.output_uri, model)
task.status = Status.ERROR if error_msg else Status.DONE
task.error_msg = error_msg
except Exception:
logger.exception("Failed to run whisper")
task.status = Status.ERROR
Expand Down

0 comments on commit b8f254c

Please sign in to comment.