streamlit-octostar-utils 0.4.2.dev15__tar.gz → 0.4.2.dev17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/PKG-INFO +1 -1
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/pyproject.toml +1 -1
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/celery.py +13 -5
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/fastapi.py +23 -9
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/nifi.py +5 -2
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/LICENSE +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/README.md +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/__init__.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/__init__.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/contents.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/parallelism.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/parser/__init__.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/parser/combine_fields.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/parser/entities_parser.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/parser/generics.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/parser/info.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/parser/linkchart_functions.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/parser/matches.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/parser/parameters.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/parser/rules.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/api_crafter/parser/signals.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/core/__init__.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/core/dict.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/core/filetypes.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/core/threading/__init__.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/core/threading/key_queue.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/core/timestamp.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/nlp/__init__.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/nlp/custom_recognizers.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/nlp/language.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/nlp/ner.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/octostar/__init__.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/octostar/client.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/octostar/context.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/octostar/permissions.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/ontology/__init__.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/ontology/inheritance.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/ontology/relationships.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/ontology/validation.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/style/__init__.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/style/common.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/threading/__init__.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/threading/async_task_manager.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/threading/session_callback_manager.py +0 -0
- {streamlit_octostar_utils-0.4.2.dev15 → streamlit_octostar_utils-0.4.2.dev17}/streamlit_octostar_utils/threading/session_state_hot_swapper.py +0 -0
|
@@ -28,7 +28,7 @@ logging.getLogger("pottery").setLevel(logging.WARNING)
|
|
|
28
28
|
from celery.app.defaults import DEFAULTS as CELERY_DEFAULTS
|
|
29
29
|
import urllib
|
|
30
30
|
|
|
31
|
-
from .fastapi import Route, CommonModels, DefaultErrorRoute
|
|
31
|
+
from .fastapi import Route, CommonModels, DefaultErrorRoute, RemoteTraceback
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
class RedisFileLock:
|
|
@@ -700,7 +700,12 @@ class CeleryExecutor(object):
|
|
|
700
700
|
|
|
701
701
|
async def get_task_result(self, task_id, remove=False):
|
|
702
702
|
def _try_get_task_data(celery_app, task_id):
|
|
703
|
-
celery_app.AsyncResult(task_id)
|
|
703
|
+
async_result = celery_app.AsyncResult(task_id)
|
|
704
|
+
if async_result.state in ("FAILURE", "RETRY", "REVOKED"):
|
|
705
|
+
exc = async_result.result
|
|
706
|
+
if not isinstance(exc, BaseException):
|
|
707
|
+
exc = RuntimeError(str(exc))
|
|
708
|
+
raise exc from RemoteTraceback(async_result.traceback)
|
|
704
709
|
|
|
705
710
|
def _read_task_data(out_folder, task_id):
|
|
706
711
|
serialized_data = CelerySerialized(folder=out_folder, redis_client=self.redis_client)
|
|
@@ -800,7 +805,7 @@ class FastAPICeleryTaskRoute(Route):
|
|
|
800
805
|
or (state not in ["SUCCESS", "FAILURE", "RETRY", "REVOKED"])
|
|
801
806
|
)
|
|
802
807
|
if state in ["FAILURE", "RETRY", "REVOKED"]:
|
|
803
|
-
error_response = DefaultErrorRoute.format_error(exc,
|
|
808
|
+
error_response = DefaultErrorRoute.format_error(exc, internal=True).body.decode("utf-8")
|
|
804
809
|
data = {
|
|
805
810
|
"task_state": state,
|
|
806
811
|
"task_id": task_id,
|
|
@@ -853,7 +858,8 @@ class CeleryErrorRoute(DefaultErrorRoute):
|
|
|
853
858
|
|
|
854
859
|
def add_default_exceptions_handler(
|
|
855
860
|
fs_app,
|
|
856
|
-
|
|
861
|
+
internal=False,
|
|
862
|
+
internal_prefixes=None,
|
|
857
863
|
excs_to_status_codes=None,
|
|
858
864
|
silenced_excs=None,
|
|
859
865
|
):
|
|
@@ -869,4 +875,6 @@ class CeleryErrorRoute(DefaultErrorRoute):
|
|
|
869
875
|
**(silenced_excs or {}),
|
|
870
876
|
}
|
|
871
877
|
|
|
872
|
-
super(CeleryErrorRoute, CeleryErrorRoute).add_default_exceptions_handler(
|
|
878
|
+
super(CeleryErrorRoute, CeleryErrorRoute).add_default_exceptions_handler(
|
|
879
|
+
fs_app, internal, internal_prefixes, status_codes, silenced,
|
|
880
|
+
)
|
|
@@ -21,7 +21,6 @@ from octostar.client import make_client
|
|
|
21
21
|
|
|
22
22
|
MAX_ERROR_MESSAGE_BYTES = 256
|
|
23
23
|
MAX_ERROR_TRACEBACK_BYTES = 10240
|
|
24
|
-
DEFAULT_PROCESSOR_SUFFIX = "main"
|
|
25
24
|
|
|
26
25
|
|
|
27
26
|
class CommonParsers(object):
|
|
@@ -268,6 +267,11 @@ class ErrorLogFilter(logging.Filter):
|
|
|
268
267
|
return True
|
|
269
268
|
|
|
270
269
|
|
|
270
|
+
class RemoteTraceback(Exception):
|
|
271
|
+
"""Holds a formatted traceback string from a remote worker process."""
|
|
272
|
+
pass
|
|
273
|
+
|
|
274
|
+
|
|
271
275
|
class DefaultErrorRoute:
|
|
272
276
|
DEFAULT_STATUS_CODE_MAPPINGS = {
|
|
273
277
|
StarletteHTTPException: lambda exc: exc.status_code,
|
|
@@ -314,7 +318,7 @@ class DefaultErrorRoute:
|
|
|
314
318
|
},
|
|
315
319
|
}
|
|
316
320
|
|
|
317
|
-
def format_error(exc, body=b"",
|
|
321
|
+
def format_error(exc, body=b"", internal=False, excs_to_status_codes=DEFAULT_STATUS_CODE_MAPPINGS):
|
|
318
322
|
"""Generic Error Handler"""
|
|
319
323
|
status_code = 500
|
|
320
324
|
for exc_type, handler in excs_to_status_codes.items():
|
|
@@ -325,27 +329,33 @@ class DefaultErrorRoute:
|
|
|
325
329
|
message = exc.message
|
|
326
330
|
except:
|
|
327
331
|
message = str(exc)
|
|
328
|
-
if
|
|
332
|
+
if internal:
|
|
329
333
|
message += "\n" + str(body)
|
|
330
334
|
if len(message) > MAX_ERROR_MESSAGE_BYTES:
|
|
331
335
|
message = message[-MAX_ERROR_MESSAGE_BYTES:]
|
|
332
336
|
try:
|
|
333
|
-
|
|
337
|
+
remote_cause = getattr(exc, "__cause__", None)
|
|
338
|
+
if isinstance(remote_cause, RemoteTraceback):
|
|
339
|
+
tcbk = str(remote_cause)
|
|
340
|
+
else:
|
|
341
|
+
tcbk = "\n".join(traceback.format_exception(exc))
|
|
334
342
|
if len(tcbk) > MAX_ERROR_TRACEBACK_BYTES:
|
|
335
343
|
tcbk = tcbk[-MAX_ERROR_TRACEBACK_BYTES:]
|
|
336
344
|
except:
|
|
337
345
|
tcbk = None
|
|
338
346
|
response_content = {"message": message, "status": "error"}
|
|
339
|
-
if
|
|
347
|
+
if internal:
|
|
348
|
+
response_content["exception_class"] = f"python.{type(exc).__module__}.{type(exc).__qualname__}"
|
|
340
349
|
response_content["traceback"] = tcbk
|
|
341
350
|
return JSONResponse(status_code=status_code, content=response_content)
|
|
342
351
|
|
|
343
|
-
async def handle_error(body: bytes, exc: Exception,
|
|
344
|
-
return DefaultErrorRoute.format_error(exc, body,
|
|
352
|
+
async def handle_error(body: bytes, exc: Exception, internal: bool, excs_to_status_codes: dict):
|
|
353
|
+
return DefaultErrorRoute.format_error(exc, body, internal, excs_to_status_codes)
|
|
345
354
|
|
|
346
355
|
def add_default_exceptions_handler(
|
|
347
356
|
fs_app,
|
|
348
|
-
|
|
357
|
+
internal=False,
|
|
358
|
+
internal_prefixes=None,
|
|
349
359
|
excs_to_status_codes=None,
|
|
350
360
|
silenced_excs=None,
|
|
351
361
|
):
|
|
@@ -353,9 +363,13 @@ class DefaultErrorRoute:
|
|
|
353
363
|
excs_to_status_codes = DefaultErrorRoute.DEFAULT_STATUS_CODE_MAPPINGS
|
|
354
364
|
if silenced_excs is None:
|
|
355
365
|
silenced_excs = DefaultErrorRoute.DEFAULT_SILENCED_EXCEPTIONS
|
|
366
|
+
internal_prefixes = tuple(internal_prefixes or [])
|
|
356
367
|
|
|
357
368
|
async def _async_handle_error(request: Request, exc: Exception):
|
|
358
|
-
|
|
369
|
+
is_internal = internal or (
|
|
370
|
+
internal_prefixes and request.url.path.startswith(internal_prefixes)
|
|
371
|
+
)
|
|
372
|
+
return await DefaultErrorRoute.handle_error(b"", exc, is_internal, excs_to_status_codes)
|
|
359
373
|
|
|
360
374
|
# Added all three since FastAPI seems to intercept some exceptions before Exception
|
|
361
375
|
fs_app.add_exception_handler(RequestValidationError, _async_handle_error)
|
|
@@ -385,9 +385,12 @@ class NifiContextManager(object):
|
|
|
385
385
|
return [entity for entity in self.jsonify(self.out_entities)["content"]]
|
|
386
386
|
|
|
387
387
|
def raise_exception(self, entity, exc):
|
|
388
|
-
error_response = DefaultErrorRoute.format_error(exc)
|
|
388
|
+
error_response = DefaultErrorRoute.format_error(exc, internal=True)
|
|
389
|
+
error_body = json.loads(error_response.body)
|
|
389
390
|
entity.request["exception"]["code"] = error_response.status_code
|
|
390
|
-
entity.request["exception"]["body"] =
|
|
391
|
+
entity.request["exception"]["body"] = error_body["message"]
|
|
392
|
+
entity.request["exception"]["exception_class"] = error_body.get("exception_class")
|
|
393
|
+
entity.request["exception"]["traceback"] = error_body.get("traceback")
|
|
391
394
|
travel_dict(entity.request["nifi_attributes"], ["invokehttp", "response", "body"], "w")(
|
|
392
395
|
entity.request["exception"]["body"]
|
|
393
396
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|