def __init__(self, project_id, write_key, q_max=5):
IEventHandler.__init__(self, q_max=q_max)
self.client_ = KeenClient(
project_id=project_id,
write_key=write_key)
def _run(self, data):
""" Procedure to run when data received from trigger thread.
Args:
data: Pass to the registered event handlers.
"""
data_source = data["source"]
at = data["at"]
upload_items = []
for label, datum in data["data"].items():
upload_item = datum
upload_item["label"] = label
upload_item["source"] = data_source
upload_item["keen"] = {"timestamp": "{}Z".format(at.isoformat())}
upload_items.append(upload_item)
self.client_.add_events({"offgrid": upload_items})
おそらく、KeenIoHandlerクラスのinitでのみKeenClientをオープンしているため、一度切断されると再接続できないことが原因。