diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-11-05 20:15:58 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-11-05 20:15:58 +0100 |
commit | ce63c337d6f8357367efd730c373cd033a568181 (patch) | |
tree | f352e647de4bab9006c7ff2a1a47a2136b715ca1 /ick2/controllerapi.py | |
parent | 30508ca876f00d5aae004ca0588258767e345480 (diff) | |
download | ick2-ce63c337d6f8357367efd730c373cd033a568181.tar.gz |
Add: advance to next step in pipeline automatically
Diffstat (limited to 'ick2/controllerapi.py')
-rw-r--r-- | ick2/controllerapi.py | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/ick2/controllerapi.py b/ick2/controllerapi.py index a7d4026..b140ce5 100644 --- a/ick2/controllerapi.py +++ b/ick2/controllerapi.py @@ -323,11 +323,13 @@ class WorkAPI(APIbase): pipeline['status'] = 'building' self._update_project(project) + index = 0 doing = { + 'worker': worker, 'project': project['project'], 'pipeline': pipeline['name'], - 'step': pipeline['actions'][0], - 'step_index': 0, + 'step': pipeline['actions'][index], + 'step_index': index, } worker_state = { @@ -364,6 +366,55 @@ class WorkAPI(APIbase): def _update_project(self, project): self._state.update_resource('projects', project['project'], project) + def update_work(self, update): + if 'worker' not in update: # pragma: no cover + raise BadUpdate('no worker specified') + + worker_state = self._get_worker(update['worker']) + doing = worker_state.get('doing', {}) + self._check_work_update(doing, update) + + project, pipeline = self._get_pipeline( + update['project'], update['pipeline']) + + if update.get('exit_code') == 0: + index = doing['step_index'] + 1 + actions = pipeline['actions'] + if index >= len(actions): + self._finish_pipeline(project, pipeline) + doing = {} + else: + doing['step_index'] = index + doing['step'] = actions[index] + + worker_state = { + 'worker': update['worker'], + 'doing': doing, + } + self._update_worker(worker_state) + + def _check_work_update(self, doing, update): # pragma: no cover + must_match = ['worker', 'project', 'pipeline'] + for name in must_match: + if name not in update: + raise BadUpdate('{} not specified'.format(name)) + if doing.get(name) != update[name]: + raise BadUpdate( + '{} differs from current work: {} vs {}'.format( + name, doing.get(name), update[name])) + + def _get_pipeline(self, project, pipeline): # pragma: no cover + projects = self._get_projects() + for p in projects: + for pl in p['pipelines']: + if pl.get('name') == pipeline: + return p, pl + raise ick2.NotFound() + + def _finish_pipeline(self, project, pipeline): + pipeline['status'] = 'idle' + self._update_project(project) + def create(self, *args, **kwargs): # pragma: no cover pass @@ -380,6 +431,12 @@ class WorkAPI(APIbase): pass +class BadUpdate(Exception): # pragma: no cover + + def __init__(self, how): + super().__init__('Work update is BAD: {}'.format(how)) + + def response(status_code, body, headers): # pragma: no cover obj = { 'status': status_code, |