diff options
author | Lars Wirzenius <liw@liw.fi> | 2018-05-25 20:46:35 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2018-05-28 18:18:38 +0300 |
commit | f18a394d0279cf2dc3a768a0470fea2201cad016 (patch) | |
tree | c57d671f0e32056a5db6fac60d3bbe90b2187e9b | |
parent | 7a4c92e7171d642a1e1fce324441710ad4d44ce9 (diff) | |
download | ick2-f18a394d0279cf2dc3a768a0470fea2201cad016.tar.gz |
Add: BuildGraph.has_more_to_do method, refactor
-rw-r--r-- | ick2/buildgraph.py | 7 | ||||
-rw-r--r-- | ick2/buildgraph_tests.py | 31 | ||||
-rw-r--r-- | ick2/workapi.py | 39 |
3 files changed, 48 insertions, 29 deletions
diff --git a/ick2/buildgraph.py b/ick2/buildgraph.py index ddcfbfb..ee52e46 100644 --- a/ick2/buildgraph.py +++ b/ick2/buildgraph.py @@ -40,6 +40,13 @@ class BuildGraph: self.actions[action_id]['status'] = status self.trigger_observer() + def has_more_to_do(self): + return ( + self.find_actions('ready') or + self.find_actions('building') or + self.find_actions('blocked') + ) + def unblock(self): blocked_ids = self.find_actions('blocked') for blocked_id in blocked_ids: diff --git a/ick2/buildgraph_tests.py b/ick2/buildgraph_tests.py index a81d2c6..e661294 100644 --- a/ick2/buildgraph_tests.py +++ b/ick2/buildgraph_tests.py @@ -166,6 +166,21 @@ class BuildGraphTests(unittest.TestCase): self.assertEqual(graph.find_actions('ready'), ['1']) self.assertEqual(graph.find_actions('blocked'), ['2']) + def test_tracks_nothing_to_do(self): + pipeline_as_dict = { + 'actions': [ + { + 'action': 'foo', + }, + { + 'action': 'bar', + }, + ], + } + pipeline = ick2.resource_from_dict(pipeline_as_dict) + graph = ick2.BuildGraph() + graph.append_pipeline(pipeline) + def test_doesnt_unblock_when_deps_are_not_done(self): pipeline_as_dict = { 'actions': [ @@ -178,12 +193,24 @@ class BuildGraphTests(unittest.TestCase): ], } pipeline = ick2.resource_from_dict(pipeline_as_dict) + graph = ick2.BuildGraph() + self.assertFalse(graph.has_more_to_do()) + graph.append_pipeline(pipeline) + graph.set_action_status('1', 'building') + self.assertEqual(graph.get_action_status('2'), 'blocked') + self.assertTrue(graph.has_more_to_do()) - graph.unblock() - self.assertEqual(graph.get_action_status('1'), 'ready') + graph.set_action_status('1', 'done') self.assertEqual(graph.get_action_status('2'), 'blocked') + self.assertTrue(graph.has_more_to_do()) + + graph.set_action_status('2', 'ready') + self.assertTrue(graph.has_more_to_do()) + + graph.set_action_status('2', 'done') + self.assertFalse(graph.has_more_to_do()) def test_unblocks_when_deps_are_done(self): pipeline_as_dict = { diff --git a/ick2/workapi.py b/ick2/workapi.py index a2d76d9..c054f0a 100644 --- a/ick2/workapi.py +++ b/ick2/workapi.py @@ -134,21 +134,20 @@ class WorkAPI(ick2.APIbase): if exit_code is not None: if exit_code == 0: - self._finish_action(graph, action_id, 'done') - if self._build_finished(graph): - self._finish_build(build, 0) - - worker.from_dict({ - 'worker': worker_id, - 'doing': {}, - }) + graph.set_action_status(action_id, 'done') + graph.unblock() + if not graph.has_more_to_do(): + build_obj.set_status('done') + build['status'] = 0 elif exit_code is not None: graph.set_action_status(action_id, 'failed') - self._finish_build(build, exit_code) - worker.from_dict({ - 'worker': worker_id, - 'doing': {}, - }) + build_obj.set_status('failed') + build['status'] = exit_code + + worker.from_dict({ + 'worker': worker_id, + 'doing': {}, + }) def _check_work_update(self, doing, update): # pragma: no cover must_match = ['worker', 'project', 'build_id'] @@ -167,20 +166,6 @@ class WorkAPI(ick2.APIbase): text = update.get(stream, '') log['log'] = log.get('log', '') + text - def _finish_action(self, graph, action_id, status): - graph.set_action_status(action_id, status) - if status == 'done': - graph.unblock() - - def _build_finished(self, graph): - return ( - graph.find_actions('ready') == [] and - graph.find_actions('blocked') == [] - ) - - def _finish_build(self, build, exit_code): - build['status'] = exit_code - def create(self, body, **kwargs): # pragma: no cover pass |