-
-
Notifications
You must be signed in to change notification settings - Fork 762
Add workflow system info in Workflow Execution context #5405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
import retrying | ||
import six | ||
|
||
from functools import wraps | ||
|
||
from orquesta import conducting | ||
from orquesta import events | ||
from orquesta import exceptions as orquesta_exc | ||
|
@@ -49,6 +51,7 @@ | |
from st2common.util import action_db as action_utils | ||
from st2common.util import date as date_utils | ||
from st2common.util import param as param_utils | ||
from st2common.util import system_info | ||
|
||
|
||
LOG = logging.getLogger(__name__) | ||
|
@@ -1561,3 +1564,38 @@ def identify_orphaned_workflows(): | |
continue | ||
|
||
return orphaned | ||
|
||
|
||
def add_system_info_to_action_context(func): | ||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
engine_info = system_info.get_process_info() | ||
|
||
# Argument will be of type WorkflowExecutionDB/ActionExecutionDB only. | ||
if kwargs.get("wf_ex_db"): | ||
ac_ex = ex_db_access.ActionExecution.get_by_id( | ||
kwargs["wf_ex_db"].action_execution | ||
) | ||
lv_ex = lv_db_access.LiveAction.get_by_id(ac_ex.liveaction["id"]) | ||
elif kwargs.get("ac_ex_db"): | ||
lv_ex = lv_db_access.LiveAction.get_by_id( | ||
kwargs["ac_ex_db"].liveaction["id"] | ||
) | ||
else: | ||
raise ValueError("Invalid message type") | ||
|
||
lv_ex.context.update({"engine_info": engine_info}) | ||
lv_db_access.LiveAction.add_or_update(lv_ex, publish=False) | ||
|
||
try: | ||
return func(*args, **kwargs) | ||
except Exception as e: | ||
raise e | ||
finally: | ||
lv_ex = lv_db_access.LiveAction.get_by_id(lv_ex.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not clear why we need this code path so we should add a comment on why this delete is here and why it's needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Kami The intention here is to add engine information to the context at the start of handling and remove it once handling is complete. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the workflow execution can be processed by 1 or more different workflow engine during its execution, it's difficult to know which workflow engine is currently handling the execution. |
||
try: | ||
del lv_ex.context["engine_info"] | ||
except KeyError: | ||
pass | ||
|
||
return wrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per my other comment, I think we should refactor this 1 or 2 separate functions and not use a decorator.