summaryrefslogtreecommitdiff
path: root/ick2/client.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-03-24 13:58:58 +0200
committerLars Wirzenius <liw@liw.fi>2018-03-30 11:52:18 +0300
commitf3506ce57ae144f1a6447940f3eb0285767d16dd (patch)
tree6bb5736a1e44f1ee5b1505cbd0206d5b3cd1a961 /ick2/client.py
parent44298d0ee50d9a844dcd6e4a46bb9f3c2b00208b (diff)
downloadick2-f3506ce57ae144f1a6447940f3eb0285767d16dd.tar.gz
Add: Reporter class for reporting progress to controller
Diffstat (limited to 'ick2/client.py')
-rw-r--r--ick2/client.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/ick2/client.py b/ick2/client.py
index bf708ae..99b8487 100644
--- a/ick2/client.py
+++ b/ick2/client.py
@@ -15,6 +15,7 @@
import json
import logging
+import time
import requests
@@ -170,6 +171,46 @@ class ControllerClient:
self._api.post(url, headers=headers, body=body)
+class Reporter: # pragma: no cover
+
+ def __init__(self, api, work):
+ self._api = api
+ self._work = dict(work)
+
+ def report(self, exit_code, stdout, stderr):
+ result = dict(self._work)
+ result['exit_code'] = exit_code
+ result['stdout'] = self.make_string(stdout)
+ result['stderr'] = self.make_string(stderr)
+ for key in result:
+ logging.debug('Reporter: result[%r]=%r', key, result[key])
+ self._api.report_work(result)
+
+ def make_string(self, thing):
+ if isinstance(thing, bytes):
+ return thing.decode('UTF-8')
+ if isinstance(thing, str):
+ return thing
+ if thing is None:
+ return thing
+ return repr(thing)
+
+ def get_work_result(self, work):
+ return {
+ 'build_id': work['build_id'],
+ 'worker': work['worker'],
+ 'project': work['project'],
+ 'pipeline': work['pipeline'],
+ 'stdout': '',
+ 'stderr': '',
+ 'exit_code': None,
+ 'timestamp': self.now(),
+ }
+
+ def now(self):
+ return time.strftime('%Y-%m-%dT%H:%M:%S')
+
+
class BlobClient:
def __init__(self):