Create a run class
create a run class:
a run has stages, get a config for each stage and produces results for each of them.
class PipelineRun():
def __init__(self, parent=None):
self.commit = self.get_commit_hash()
self.hash = self.generate_hash(); # class function
if parent:
self.stages = parent.stages
self.products = parent.products
else:
self.stages = []
self.products = []
self.parent = parent
self.childs = []
def register_stage(self, stage_name, stage_procedure, stage_config):
if stage_procedure.has_source_commit():
stage = Stage(stage_name, stage_procedure, stage_config)
self.stages.append(stage)
else:
raise RunTimeError("The stage can not be registered, the procedure does not have a source commit")
def run(self):
stages_to_run = [stage for stage in self.stages if not stage.done]
for stage in stages_to_run:
product = stage.run()
self.products.append(product)
stage.done = True
class Stage():
def __init__(self, name, procedure, config):
self.done = False
self.name = name
self.procedure = procedure
self.config = config
def run(self):
product = self.procedure(self.config)
return(product)