summaryrefslogtreecommitdiff
path: root/ick2/client.py
diff options
context:
space:
mode:
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):