-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pipeline.py
72 lines (56 loc) · 3.08 KB
/
Pipeline.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
from Stage import *
from collections import OrderedDict
import logging
import time
logging.basicConfig(level=logging.ERROR, format="[%(levelname)s] [%(created)f] [%(filename)s] %(message)s")
class SequentialPipeline(object):
def __init__(self):
self.io = Map()
self.static_io = Map()
self._setup_pipeline = OrderedDict()
self._pipeline = OrderedDict()
self._cleanup_pipeline = OrderedDict()
logging.debug("Created instance of SequentialPipeline\nio: {}\nstatic_io: {}".format(self.io._map, self.static_io._map))
def add_setup_stage(self, stage_name, stage):
if stage_name not in self._setup_pipeline.keys():
self._setup_pipeline[stage_name] = stage
logging.debug("'{}' added to setup pipeline [input_keys: {}\toutput_keys: {}]".format(stage_name,
stage.get_registered_input_keys(), stage.get_registered_output_keys()))
else:
logging.warn("Duplicate setup stage name '{}'. Not added to setup pipeline".format(stage_name))
def add_stage(self, stage_name, stage):
if stage_name not in self._pipeline.keys():
self._pipeline[stage_name] = stage
logging.debug("'{}' added to pipeline [input_keys: {}\toutput_keys: {}]".format(stage_name,
stage.get_registered_input_keys(), stage.get_registered_output_keys()))
else:
logging.warn("Duplicate stage name '{}'. Not added to pipeline".format(stage_name))
def execute_setup(self):
logging.debug("Setting pipeline for execution")
for (stage_name, stage) in self._setup_pipeline.items():
logging.debug("Loaded stage '{}'".format(stage_name))
input_keys = stage.get_registered_input_keys()
output_keys = stage.get_registered_output_keys()
outcome = stage.execute(MapAccess(mapObj=self.io, input_keys=input_keys, output_keys=output_keys), self.static_io)
if outcome == status.FAILURE:
logging.error("'{}' failed to execute".format(stage_name))
return status.FAILURE
elif outcome == status.SUCCESS:
logging.debug("'{}' successfully executed".format(stage_name))
pass
logging.debug("Setup complete")
def execute(self):
logging.debug("Executing pipeline")
for (stage_name, stage) in self._pipeline.items():
logging.debug("Loaded stage '{}'".format(stage_name))
input_keys = stage.get_registered_input_keys()
output_keys = stage.get_registered_output_keys()
outcome = stage.execute(MapAccess(mapObj=self.io, input_keys=input_keys, output_keys=output_keys), self.static_io)
if outcome == status.FAILURE:
logging.error("'{}' failed to execute".format(stage_name))
return status.FAILURE
elif outcome == status.SUCCESS:
logging.debug("'{}' successfully executed".format(stage_name))
pass
logging.debug("Execution complete")
return status.SUCCESS