-
Notifications
You must be signed in to change notification settings - Fork 1
/
colonies_monad.py
63 lines (54 loc) · 2.07 KB
/
colonies_monad.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
from pycolonies import Colonies
from pycolonies import Workflow
from pycolonies import func_spec
import copy
class Function:
def __init__(self,
func,
colonyname,
executortype,
priority=0,
maxexectime=200,
maxretries=3,
maxwaittime=-1):
self.func_spec = func_spec(func=func,
args=[],
colonyname=colonyname,
executortype=executortype,
priority=priority,
maxexectime=maxexectime,
maxretries=maxretries,
maxwaittime=maxwaittime)
if isinstance(func, str):
self.name = func
else:
self.name = func.__name__
class ColoniesMonad:
def __init__(self,
colonies: Colonies,
colonyname,
executor_prvkey):
self.wf = Workflow(colonyname=colonyname)
self.colonyname = colonyname
self.executor_prvkey = executor_prvkey
self.prev_func = None
self.colonies = colonies
def __ror__(self, other):
pass
def __rshift__(self, f: Function): # bind function
if self.prev_func is None:
self.wf.functionspecs.append(f.func_spec)
self.prev_func = f.name
else:
fs = copy.deepcopy(f.func_spec)
fs.conditions.dependencies = [self.prev_func]
self.wf.functionspecs.append(fs)
self.prev_func = f.name
return self
def unwrap(self):
processgraph = self.colonies.submit_workflow(self.wf, self.executor_prvkey)
last_process = self.colonies.find_process(self.prev_func, processgraph.processids, self.executor_prvkey)
process = self.colonies.wait(last_process, 100, self.executor_prvkey)
if len(process.output)>0:
return process.output[0]
return ""