def ping(self, exp_key, status, _duplex=True, burn=True):
     # todo: add configuration for early termination
     if self.local_server:
         signals = self.local_server.ping(exp_key, status)
         return deserialize(signals) if _duplex else None
     else:
         # todo: make the json serialization more robust. Not priority b/c this' client-side.
         ping_data = PingData(exp_key, status, burn=burn)._asdict()
         req = self.session.post(self.ping_url, json=ping_data)
         if _duplex:
             response = req.result()
             # note: I wonder if we should raise if the response is non-ok.
             return deserialize(response.text) if response.ok else None
Beispiel #2
0
 async def log_handler(self, req):
     import sanic
     from collections import Sequence
     if req.files:
         file, = req.files['file']
         print(f"uploading: {file.name} len: {len(file.body)}")
         self.log(file.name, file.body, "byte", LogOptions(overwrite=True))
         return sanic.response.json(dict(name=file.name, length=len(file.body), overwrite=True))
     elif not req.json:
         cprint(f'request json is empty: {req.text}', 'red')
         return sanic.response.text("Request json is empty")
     log_entry = LogEntry(**req.json)
     print(f"writing: {log_entry.key} type: {log_entry.type} options: {log_entry.options}")
     data = deserialize(log_entry.data)
     if not log_entry:
         options = None
     elif log_entry.options is None:
         options = log_entry.options
     elif isinstance(log_entry.options, Sequence):
         options = LogOptions(*log_entry.options)
     elif isinstance(log_entry.options, dict):
         options = LogOptions(**log_entry.options)
     else:
         options = None
     self.log(log_entry.key, data, log_entry.type, options)
     return sanic.response.text('ok')
Beispiel #3
0
 def log_handler(self, req):
     if not req.json:
         print(f'request json is empty: {req.text}')
         return req.Response(text="Reuqest json is empty")
     log_entry = LogEntry(**req.json)
     print("writing: {} type: {} options: {}".format(log_entry.key, log_entry.type, log_entry.options))
     data = deserialize(log_entry.data)
     self.log(log_entry.key, data, log_entry.type, LogOptions(*log_entry.options))
     return req.Response(text='ok')
 def _get(self, key, dtype, **options):
     if self.local_server:
         return self.local_server.load(key, dtype, **options)
     else:
         json = LoadEntry(key, dtype, **options)._asdict()
         # note: reading stuff from the server is always synchronous via the result call.
         res = self.session.get(self.url, json=json).result()
         # todo: better error handling.
         return deserialize(res.text)
Beispiel #5
0
 def _get(self, key, dtype):
     if self.local_server:
         return self.local_server.load(key, dtype)
     else:
         json = LoadEntry(key, dtype)._asdict()
         # note: reading stuff from the server is always synchronous via the result call.
         res = self.session.get(self.url, json=json).result()
         result = deserialize(res.text)
         return result
Beispiel #6
0
 async def log_handler(self, req):
     import sanic
     if not req.json:
         print(f'request json is empty: {req.text}')
         return sanic.response.text("Reuqest json is empty")
     log_entry = LogEntry(**req.json)
     print("writing: {} type: {} options: {}".format(log_entry.key, log_entry.type, log_entry.options))
     data = deserialize(log_entry.data)
     options = log_entry.options if log_entry.options is None else LogOptions(*log_entry.options)
     self.log(log_entry.key, data, log_entry.type, options)
     return sanic.response.text('ok')