Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lightflow/models/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ class Dag:
schema (dict): A dictionary with the definition of the task graph.
"""
def __init__(self, name, *, autostart=True, queue=DefaultJobQueueName.Dag,
schema=None):
schema=None,
graph=None):
self._name = name
self._autostart = autostart
self._queue = queue
self._schema = schema
self._graph = graph

self._copy_counter = 0
self._workflow_name = None
Expand Down Expand Up @@ -114,7 +116,10 @@ def run(self, config, workflow_id, signal, *, data=None):
DirectedAcyclicGraphInvalid: If the graph is not a dag (e.g. contains loops).
ConfigNotDefinedError: If the configuration for the dag is empty.
"""
graph = self.make_graph(self._schema)
if not self._graph:
graph = self.make_graph(self._schema)
else:
graph = self._graph

# pre-checks
self.validate(graph)
Expand Down Expand Up @@ -252,8 +257,7 @@ def validate(self, graph):
if not nx.is_directed_acyclic_graph(graph):
raise DirectedAcyclicGraphInvalid(graph_name=self._name)

@staticmethod
def make_graph(schema):
def make_graph(self, schema):
""" Construct the task graph (dag) from a given schema.

Parses the graph schema definition and creates the task graph. Tasks are the
Expand Down Expand Up @@ -315,7 +319,8 @@ def make_graph(schema):
else:
graph.add_node(parent)

return graph
self._graph = graph
return self._graph

def __deepcopy__(self, memo):
""" Create a copy of the dag object.
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pytest
pytest>=3.6
pytest-cov
flake8