mirror of
https://github.com/ansible/awx.git
synced 2026-03-05 02:31:03 -03:30
rework wf cycle detection for convergence
This commit is contained in:
@@ -8,7 +8,7 @@ from django.db import migrations, models
|
|||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('main', '0049_v330_validate_instance_capacity_adjustment'),
|
('main', '0050_v340_drop_celery_tables'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
@@ -123,26 +123,24 @@ class SimpleDAG(object):
|
|||||||
|
|
||||||
def has_cycle(self):
|
def has_cycle(self):
|
||||||
node_objs = [node['node_object'] for node in self.get_root_nodes()]
|
node_objs = [node['node_object'] for node in self.get_root_nodes()]
|
||||||
nodes_visited = set([])
|
node_objs_visited = set([])
|
||||||
path = set([])
|
path = set([])
|
||||||
stack = node_objs
|
stack = node_objs
|
||||||
path_direction = 'DOWN'
|
|
||||||
|
|
||||||
while stack:
|
while stack:
|
||||||
node_obj = stack.pop()
|
node_obj = stack.pop()
|
||||||
|
|
||||||
children = self.get_dependencies(node_obj)
|
children = [node['node_object'] for node in self.get_dependencies(node_obj)]
|
||||||
for child in children:
|
children_to_add = filter(lambda node_obj: node_obj not in node_objs_visited, children)
|
||||||
if child['node_object'] not in nodes_visited:
|
|
||||||
stack.append(child['node_object'])
|
|
||||||
if node_obj in path:
|
|
||||||
return True
|
|
||||||
|
|
||||||
if not children:
|
if children_to_add:
|
||||||
path_direction = 'UP'
|
if node_obj in path:
|
||||||
|
return True
|
||||||
if path_direction == 'DOWN':
|
|
||||||
path.add(node_obj)
|
path.add(node_obj)
|
||||||
elif path_direction == 'UP':
|
stack.append(node_obj)
|
||||||
|
stack.extend(children_to_add)
|
||||||
|
else:
|
||||||
|
node_objs_visited.add(node_obj)
|
||||||
path.discard(node_obj)
|
path.discard(node_obj)
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user