summaryrefslogtreecommitdiff
path: root/ick2/workapi.py
diff options
context:
space:
mode:
Diffstat (limited to 'ick2/workapi.py')
-rw-r--r--ick2/workapi.py62
1 files changed, 33 insertions, 29 deletions
diff --git a/ick2/workapi.py b/ick2/workapi.py
index d254515..a2d76d9 100644
--- a/ick2/workapi.py
+++ b/ick2/workapi.py
@@ -51,17 +51,23 @@ class WorkAPI(ick2.APIbase):
build['status'] = 'building'
build['worker'] = worker_id
- self._start_log(build_id)
+ build_obj = ick2.Build(build)
+ graph = build_obj.get_graph()
+ action_id = self._pick_next_action(graph)
+ if action_id is None: # pragma: no cover
+ return {}
+
+ graph.set_action_status(action_id, 'building')
+ action = graph.get_action(action_id)
- actions = build['actions']
- current_action = build['current_action']
doing = {
'build_id': build_id,
'build_number': build['build_number'],
'worker': worker_id,
'project': build['project'],
'parameters': build['parameters'],
- 'step': actions[current_action],
+ 'action_id': action_id,
+ 'step': action,
'log': build['log'],
}
@@ -102,13 +108,11 @@ class WorkAPI(ick2.APIbase):
return build['build_id']
return None
- def _start_log(self, build_id):
- ick2.log.log('info', msg_text='Starting new log', build_id=build_id)
- with self._trans.new('log', build_id) as r:
- r.from_dict({
- 'build_id': build_id,
- 'log': '',
- })
+ def _pick_next_action(self, graph):
+ action_ids = graph.find_actions('ready')
+ if not action_ids: # pragma: no cover
+ return None
+ return action_ids[0]
def update_work(self, update, **kwargs):
try:
@@ -121,24 +125,25 @@ class WorkAPI(ick2.APIbase):
with self._trans.modify('workers', worker_id) as worker:
with self._trans.modify('builds', build_id) as build:
+ build_obj = ick2.Build(build)
+ graph = build_obj.get_graph()
doing = worker.get('doing', {})
self._check_work_update(doing, update)
self._append_to_build_log(update)
+ action_id = doing['action_id']
if exit_code is not None:
if exit_code == 0:
- action = self._move_to_next_action(build)
- if action is None:
- doing = {}
- self._finish_build(build, exit_code)
- else:
- doing['step'] = action
+ self._finish_action(graph, action_id, 'done')
+ if self._build_finished(graph):
+ self._finish_build(build, 0)
worker.from_dict({
'worker': worker_id,
- 'doing': doing,
+ 'doing': {},
})
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,
@@ -160,22 +165,21 @@ class WorkAPI(ick2.APIbase):
with self._trans.modify('log', build_id) as log:
for stream in ['stdout', 'stderr']:
text = update.get(stream, '')
- if text is not None:
- log['log'] += text
+ log['log'] = log.get('log', '') + text
- def _move_to_next_action(self, build):
- actions = build['actions']
- current_action = build['current_action']
- if current_action + 1 >= len(actions):
- return None
+ def _finish_action(self, graph, action_id, status):
+ graph.set_action_status(action_id, status)
+ if status == 'done':
+ graph.unblock()
- index = current_action + 1
- build['current_action'] = index
- return actions[index]
+ 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
- build['current_action'] = None
def create(self, body, **kwargs): # pragma: no cover
pass