Skip to content

Commit

Permalink
DONE
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng committed Nov 21, 2024
1 parent f2b7c41 commit 99545fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions iwf/tests/worker_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import traceback
from threading import Thread

from flask import Flask, request
Expand All @@ -13,6 +12,8 @@
WorkerService,
)

# NOTE: set this to true when debugging(using breakpoints)
# so that it keep the thread running so that we can see the error in history
debug_mode: bool = False

registry = Registry()
Expand Down Expand Up @@ -52,8 +53,7 @@ def handle_rpc():
# the WebUI will be able to show you the error with stacktrace
@_flask_app.errorhandler(Exception)
def internal_error(exception):
print("encounter errors:", exception)
return traceback.format_exc(), 500
return _worker_service.handle_worker_error(exception), 500


_webApp = Thread(target=_flask_app.run, args=("0.0.0.0", 8802))
Expand Down
16 changes: 16 additions & 0 deletions iwf/worker_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import traceback
import typing
from dataclasses import dataclass

Expand Down Expand Up @@ -47,6 +48,21 @@ def __init__(
self._registry = registry
self._options = options

@staticmethod
def handle_worker_error(exception: Exception):
"""
handle the exception/error of worker.
Example usage (in Flask):
@_flask_app.errorhandler(Exception)
def internal_error(exception):
return _worker_service.handle_worker_error(exception), 500
"""
stacktrace = traceback.format_exc()
index = stacktrace.index("iwf-python-sdk/iwf/worker_service.py")
return "WorkerExecutionError: {0}; StackTrace:{1}".format(
exception, stacktrace[index:]
)

def handle_workflow_worker_rpc(
self,
request: WorkflowWorkerRpcRequest,
Expand Down

0 comments on commit 99545fd

Please sign in to comment.