-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathcontinuousactivity.py
73 lines (57 loc) · 2.98 KB
/
continuousactivity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import time
import sys
from ..utils import DataikuException
class DSSContinuousActivity(object):
"""
A handle to interact with the execution of a continuous recipe on the DSS instance.
.. important::
Do not create this class directly, instead use :meth:`dataikuapi.dss.project.DSSProject.get_continuous_activity`
"""
def __init__(self, client, project_key, recipe_id):
self.client = client
self.recipe_id = recipe_id
self.project_key = project_key
def start(self, loop_params={}):
"""
Start the continuous activity
:param dict loop_params: controls how the recipe is restarted after a failure, and the delay before
the restarting. Default is to restart indefinitely without delay. Fields are:
* **abortAfterCrashes** : when reaching this number of failures, the recipe isn't restarted anymore. Use -1 as 'no limit on number of failures'
* **initialRestartDelayMS** : initial delay to wait before restarting after a failure
* **restartDelayIncMS** : increase to the delay before restarting upon subsequent failures
* **maxRestartDelayMS** : max delay before restarting after failure
"""
return self.client._perform_json(
"POST", "/projects/%s/continuous-activities/%s/start" % (self.project_key, self.recipe_id), body=loop_params)
def stop(self):
"""
Stop the continuous activity.
"""
self.client._perform_empty(
"POST", "/projects/%s/continuous-activities/%s/stop" % (self.project_key, self.recipe_id))
def get_status(self):
"""
Get the current status of the continuous activity.
Usage example:
.. code-block:: python
# stop a continuous activity via its future
from dataikuapi.dss.future import DSSFuture
activity = project.get_continuous_activity("my_continuous_recipe")
status = activity.get_status()
future = DSSFuture(a.client, status["mainLoopState"]['futureId'], status["mainLoopState"]['futureInfo'])
future.abort()
# this is equivalent to simply stop()
activity.stop()
:return: the state of the continuous activity. The state as requested by the use is stored in a **desiredState**
field (values: 'STARTED' or 'STOPPED'), and the current effective state in a **mainLoopState** sub-dict.
:rtype: dict
"""
return self.client._perform_json(
"GET", "/projects/%s/continuous-activities/%s/" % (self.project_key, self.recipe_id))
def get_recipe(self):
"""
Get a handle on the associated recipe.
:rtype: :class:`dataikuapi.dss.recipe.DSSRecipe`
"""
from .recipe import DSSRecipe
return DSSRecipe(self.client, self.project_key, self.recipe_id)