Skip to content

Commit 403f77f

Browse files
committed
Add client for "get-recipe-status" API
1 parent e5051f7 commit 403f77f

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

dataikuapi/dss/recipe.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ def set_definition_and_payload(self, definition):
4949
"PUT", "/projects/%s/recipes/%s" % (self.project_key, self.recipe_name),
5050
body=definition.data)
5151

52+
########################################################
53+
# Recipe status
54+
########################################################
55+
56+
def get_status(self):
57+
"""
58+
Gets the status of this recipe (status messages, engines status, ...)
59+
60+
:return: an object to interact
61+
:rtype: :class:`dataikuapi.dss.recipe.DSSRecipeStatus`
62+
"""
63+
data = self.client._perform_json(
64+
"GET", "/projects/%s/recipes/%s/status" % (self.project_key, self.recipe_name))
65+
return DSSRecipeStatus(self.client, data)
66+
5267
########################################################
5368
# Recipe metadata
5469
########################################################
@@ -89,6 +104,54 @@ def get_object_discussions(self):
89104
"""
90105
return DSSObjectDiscussions(self.client, self.project_key, "RECIPE", self.recipe_name)
91106

107+
class DSSRecipeStatus(object):
108+
def __init__(self, client, data):
109+
"""Do not call that directly, use :meth:`dataikuapi.dss.recipe.DSSRecipe.get_status`"""
110+
self.client = client
111+
self.data = data
112+
113+
def get_selected_engine_details(self):
114+
"""
115+
Gets the selected engine for this recipe (for recipes that support engines)
116+
117+
:returns: a dict of the details of the selected recipe. The dict will contain at least fields 'type' indicating
118+
which engine it is, "statusWarnLevel" which indicates whether the engine is OK / WARN / ERROR
119+
:rtype: dict
120+
"""
121+
if not "selectedEngine" in self.data:
122+
raise ValueError("This recipe doesn't have a selected engine")
123+
return self.data["selectedEngine"]
124+
125+
def get_engines_details(self):
126+
"""
127+
Gets details about all possible engines for this recipe (for recipes that support engines)
128+
129+
:returns: a list of dict of the details of each possible engine. The dict for each engine
130+
will contain at least fields 'type' indicating
131+
which engine it is, "statusWarnLevel" which indicates whether the engine is OK / WARN / ERROR
132+
:rtype: list
133+
"""
134+
if not "engines" in self.data:
135+
raise ValueError("This recipe doesn't have engines")
136+
return self.data["engines"]
137+
138+
def get_status_severity(self):
139+
"""Returns whether the recipe is in SUCCESS, WARNING or ERROR status
140+
141+
:rtype: string
142+
"""
143+
return self.data["allMessagesForFrontend"]["maxSeverity"]
144+
145+
def get_status_messages(self):
146+
"""
147+
Returns status messages for this recipe.
148+
149+
:returns: a list of dict, for each status message. Each dict represents a single message,
150+
and contains at least a "severity" field (SUCCESS, WARNING or ERROR)
151+
and a "message" field
152+
:rtype: list
153+
"""
154+
return self.data["allMessagesForFrontend"]["messages"]
92155

93156
class DSSRecipeDefinitionAndPayload(object):
94157
"""

0 commit comments

Comments
 (0)