-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into DOG-4448-file-extractor-simplify-extractio…
…n-failure-analysis
- Loading branch information
Showing
7 changed files
with
352 additions
and
5 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
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,70 @@ | ||
import typing | ||
from enum import Enum | ||
from types import TracebackType | ||
from uuid import uuid4 | ||
|
||
from cognite.extractorutils.util import now | ||
|
||
if typing.TYPE_CHECKING: | ||
from .base import Extractor | ||
|
||
|
||
class ErrorLevel(Enum): | ||
warning = "warning" | ||
error = "error" | ||
fatal = "fatal" | ||
|
||
|
||
class Error: | ||
def __init__( | ||
self, | ||
level: ErrorLevel, | ||
description: str, | ||
details: str | None, | ||
task_name: str | None, | ||
extractor: "Extractor", | ||
) -> None: | ||
self.level = level | ||
self.description = description | ||
self.details = details | ||
|
||
self.external_id = str(uuid4()) | ||
self.start_time = now() | ||
self.end_time: int | None = None | ||
|
||
self._extractor = extractor | ||
self._task_name = task_name | ||
|
||
self._extractor._report_error(self) | ||
|
||
def instant(self) -> None: | ||
# Only end the error once | ||
if self.end_time is not None: | ||
return | ||
|
||
self.end_time = self.start_time | ||
|
||
# Re-add in case the error has already been reported and dict cleared | ||
self._extractor._report_error(self) | ||
|
||
def finish(self) -> None: | ||
# Only end the error once | ||
if self.end_time is not None: | ||
return | ||
|
||
self.end_time = now() | ||
|
||
# Re-add in case the error has already been reported and dict cleared | ||
self._extractor._report_error(self) | ||
|
||
def __enter__(self) -> "Error": | ||
return self | ||
|
||
def __exit__( | ||
self, | ||
exc_type: typing.Type[BaseException] | None, | ||
exc_val: BaseException | None, | ||
exc_tb: TracebackType | None, | ||
) -> bool: | ||
self.finish() | ||
return exc_val is None |
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.