diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-11-26 16:41:33 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-11-26 17:59:59 +0100 |
commit | 964e646b2c26bcb007390dc6af625835f98887ec (patch) | |
tree | ae7ea88c5894ad71167959ed82d81b984f78b5e7 /ick2/workapi.py | |
parent | f0ccb8150a67b10e11b3358d6385e31619e6d1e3 (diff) | |
download | ick2-964e646b2c26bcb007390dc6af625835f98887ec.tar.gz |
Update: project and work apis to handle named pipelines
Diffstat (limited to 'ick2/workapi.py')
-rw-r--r-- | ick2/workapi.py | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/ick2/workapi.py b/ick2/workapi.py index 5935fe9..f84e355 100644 --- a/ick2/workapi.py +++ b/ick2/workapi.py @@ -46,7 +46,7 @@ class WorkAPI(ick2.APIbase): doing = {} else: pipeline['status'] = 'building' - self._projects.update_project(project) + self._update_pipeline(project, pipeline) build_id = project.get('build_id', 0) + 1 project['build_id'] = build_id @@ -78,11 +78,30 @@ class WorkAPI(ick2.APIbase): def _pick_triggered_pipeline(self): projects = self._projects.get_projects() for project in projects: - for pipeline in project['pipelines']: - if pipeline.get('status') == 'triggered': - return project, pipeline + for name in project['pipelines']: + pp = self._pipeline_instance_name(project['project'], name) + try: + pl = self._state.get_resource('pipeline_instances', pp) + except ick2.NotFound: + pass + else: + if pl.get('status') == 'triggered': + pt = self._state.get_resource('pipelines', name) + return project, pt return None, None + def _pipeline_instance_name(self, project_name, pipeline_name): + return '{} {}'.format(project_name, pipeline_name) + + def _update_pipeline(self, project, pipeline): + pp = self._pipeline_instance_name(project['project'], pipeline['name']) + try: + self._state.get_resource('pipeline_instances', pp) + except ick2.NotFound: # pragma: no cover + self._state.add_resource('pipeline_instances', pp, pipeline) + else: + self._state.update_resource('pipeline_instances', pp, pipeline) + def _start_build(self, project, pipeline, worker, build_id): ick2.log.log('info', msg_text='Starting new build', build_id=build_id) build = { @@ -136,6 +155,7 @@ class WorkAPI(ick2.APIbase): doing['step_index'] = index doing['step'] = actions[index] self._projects.update_project(project) + self._update_pipeline(project, pipeline) worker_state = { 'worker': update['worker'], @@ -146,7 +166,7 @@ class WorkAPI(ick2.APIbase): assert isinstance(exit_code, int) assert exit_code != 0 pipeline['status'] = 'idle' - self._projects.update_project(project) + self._update_pipeline(project, pipeline) self._finish_build(update) worker_state = { @@ -168,9 +188,10 @@ class WorkAPI(ick2.APIbase): def _get_pipeline(self, project, pipeline): # pragma: no cover projects = self._projects.get_projects() for p in projects: - for pl in p['pipelines']: - if pl.get('name') == pipeline: - return p, pl + for name in p['pipelines']: + if name == pipeline: + pt = self._state.get_resource('pipelines', name) + return p, pt raise ick2.NotFound() def _append_to_build_log(self, update): |