Commit 90893be9 authored by Janez K's avatar Janez K
Browse files

work on workflow runner

parent 79bb11f8
class WidgetRunner():
def __init__(self,widget,workflow_runner=None):
self.widget = widget
self.inputs = widget.inputs.all()
self.output = widget.outputs.all()
self.input_data = {}
self.output_data = {}
self.workflow_runner = workflow_runner
def run(self):
class WorkflowRunner():
def __init__(self,workflow,clean=False):
self.workflow = workflow
self.connections = workflow.connections.all().select_related('input','output')
self.widgets = workflow.widgets.all().prefetch_related('inputs','outputs')
self.clean = clean
if self.clean:
for w in self.widgets:
w.finished = False
def finished_widgets(self):
finished_widgets = []
for w in self.widgets:
if w.finished:
return finished_widgets
def unfinished_widgets(self):
unfinished_widgets = []
for w in self.widgets:
if not w.finished and not w.running:
return unfinished_widgets
def runnable_widgets(self):
""" a widget is runnable if all widgets connected before
it are finished (i.e. widgets that have outputs that
are connected to this widget's input) """
finished_widget_ids = [ for w in self.finished_widgets]
runnable = []
for w in self.unfinished_widgets:
ready_to_run = True
for c in self.connections:
if c.input.widget_id == and not c.output.widget_id in finished_widget_ids:
ready_to_run = False
if ready_to_run:
return runnable
def run(self):
runnable_widgets = self.runnable_widgets
while len(runnable_widgets)>0:
for w in runnable_widgets:
wr = WidgetRunner(w,self)
runnable_widgets = self.runnable_widgets
\ No newline at end of file
......@@ -167,7 +167,7 @@ class Workflow(models.Model):
return unfinished_list
def run_for_loop(self):
"""def run_for_loop(self):
widgets = self.widgets.all().prefetch_related('inputs','outputs')
connections = self.connections.all().select_related('input','output','input__widget','output__widget')
fi = None
......@@ -188,9 +188,9 @@ class Workflow(models.Model):
finished = []
unfinished_list = []
fi.finished = True
proper_output = fi.outputs.all()[0]
proper_output = fi.outputs.all()[0]"""
def run_for_loop_slow(self):
def run_for_loop(self):
""" Method runs the workflow for loop. The use of [0] at the end of lines is because
there can be only one for loop in one workflow. This way we take the first one. """
#clear for_input and for_output
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment