Skip to content

Commit

Permalink
chore: Add output id for failed jobs (#110)
Browse files Browse the repository at this point in the history
* chore: Add output id for failed jobs

* refactor: Reformat using black

* fix: Update tests

Overlays are returned as tar-files now

* fix: Update tests

* chore: Update v3 tools logging
  • Loading branch information
radmiratbrighterai authored Dec 2, 2024
1 parent 342c84a commit 6ac52de
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=9.2.0
VERSION=9.3.0

SHELL := /bin/bash

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "redact"
version = "9.2.0"
version = "9.3.0"
description = "Command-line and Python client for Brighter AI's Redact"
authors = ["brighter AI <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion redact/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Python client for "brighter Redact"
"""

__version__ = "9.2.0"
__version__ = "9.3.0"

from .errors import RedactConnectError, RedactResponseError
from .v4.data_models import (
Expand Down
20 changes: 16 additions & 4 deletions redact/v3/tools/redact_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ def redact_file(
for warning in job_status.warnings:
log.warning(f"Warning for '{file_path}': {warning}")
if job_status.state == JobState.failed:
log.error(f"Job failed for '{file_path}': {job_status.error}")
error_output_id = (
f" {job_status.output_id}"
if job_status and job_status.output_id
else ""
)
log.error(
f"Job{error_output_id} failed for '{file_path}': {job_status.error}"
)
return job_status

# stream result to file
Expand All @@ -133,9 +140,14 @@ def redact_file(
log.debug(f"Deleting {file_path}")
Path(file_path).unlink()

# delete job
if auto_delete_job:
job.delete()
try:
# delete job
if auto_delete_job:
log.debug(f"Deleting job {job.output_id}")
job.delete()
except UnboundLocalError:
# if the starting the job failed, there is no job variable and this Exception will be thrown
pass

return job_status

Expand Down
9 changes: 8 additions & 1 deletion redact/v4/tools/redact_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ def redact_file(
for warning in job_status.warnings:
log.warning(f"Warning for '{file_path}': {warning}")
if job_status.state == JobState.failed:
log.error(f"Job failed for '{file_path}': {job_status.error}")
error_output_id = (
f" {job_status.output_id}"
if job_status and job_status.output_id
else ""
)
log.error(
f"Job{error_output_id} failed for '{file_path}': {job_status.error}"
)
return job_status

# stream result to file
Expand Down
4 changes: 2 additions & 2 deletions tests/v3/functional/test_redact_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_redact_file_video_correct_file_ending_for_overlays(
file_folder = video_path.parent
assert len(os.listdir(file_folder)) == 2

result_file = file_folder / f"{video_path.stem}_redacted.apng"
result_file = file_folder / f"{video_path.stem}_redacted.tar"
assert result_file.exists()

def test_redact_folder_video_correct_file_ending_for_overlays(
Expand All @@ -112,4 +112,4 @@ def test_redact_folder_video_correct_file_ending_for_overlays(
p.relative_to(output_path) for p in output_path.rglob("*.*")
]
for file in files_in_out_dir:
assert file.suffix == ".apng"
assert file.suffix == ".tar"
4 changes: 2 additions & 2 deletions tests/v4/functional/test_redact_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_delete_method_called_on_error(
"output_type,service,file_extension",
[
[OutputType.labels, ServiceType.redact_area, ".json"],
[OutputType.overlays, ServiceType.blur, ".apng"],
[OutputType.overlays, ServiceType.blur, ".tar"],
],
)
def test_video_correct_file_ending(
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_video_correct_file_ending(
"output_type,service,file_extension",
[
[OutputType.labels, ServiceType.redact_area, ".json"],
[OutputType.overlays, ServiceType.blur, ".apng"],
[OutputType.overlays, ServiceType.blur, ".tar"],
],
)
def test_redact_folder_video_correct_file_ending_for_overlays(
Expand Down

0 comments on commit 6ac52de

Please sign in to comment.