-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtask.py
More file actions
46 lines (28 loc) · 1.21 KB
/
task.py
File metadata and controls
46 lines (28 loc) · 1.21 KB
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
class Task():
def __init__(self, settings={}):
self._type = "task"
self._settings = self._validate_settings(settings)
with open("./soar_scripts/"+self._settings["script"], "r") as f:
self._code = f.read()
def _validate_settings(self, settings):
required = ["id", "name", "script", "entry_point", "imports"]
for req in required:
if req not in settings:
raise ValueError("{} not in task settings".format(req))
return settings
def execute(self, data={}):
for imp in self._settings["imports"]:
globals()[imp] = __import__(imp)
exec(self._code)
dummy_func = locals()[self._settings["entry_point"]]
return dummy_func(data=data, settings=self._settings)
class DistributedTask():
def __init__(self, settings={}):
self._type = "task"
self._settings = self._validate_settings(settings)
def _validate_settings(self, settings):
required = ["id", "name", "script", "entry_point", "imports", "outputs"]
for req in required:
if req not in settings:
raise ValueError("{} not in task settings".format(req))
return settings