keenioへのデータアップロードが止まる
Opened this issue · 1 comments
dodo5522 commented
おそらく、KeenIoHandlerクラスの__init__でのみKeenClientをオープンしているため、一度切断されると再接続できないことが原因。
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})
dodo5522 commented
- event-listenerパッケージを使う
- 接続が切れた場合の再接続処理を、例外キャッチした時点で行うように修正する