Skip to content

Commit

Permalink
Merge pull request #237 from krkeegan/DB_Retry_Timeout
Browse files Browse the repository at this point in the history
Don't Retry DB Get But Increase Timeout; Retry on DB Modify
  • Loading branch information
krkeegan authored Dec 11, 2020
2 parents cb6726c + 1dcb921 commit e036b3d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 19 additions & 2 deletions insteon_mqtt/handler/DeviceDbGet.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DeviceDbGet(Base):
Each reply is passed to the callback function set in the constructor
which is usually a method on the device to update it's database.
"""
def __init__(self, device_db, on_done, num_retry=0):
def __init__(self, device_db, on_done, num_retry=3, time_out=5):
"""Constructor
The on_done callback has the signature on_done(success, msg, entry)
Expand All @@ -38,8 +38,21 @@ def __init__(self, device_db, on_done, num_retry=0):
handler times out without returning Msg.FINISHED.
This count does include the initial sending so a
retry of 3 will send once and then retry 2 more times.
Retries only apply to the initial get request and the ack
of that request. The subsequent messages are streamed from
the device without further requests. If the handler times
out after the initial request, there is no way to recover,
besides starting the request over again.
time_out (int): Timeout in seconds. The regular timeout applies to
the initial request. The subsequent messages are
streamed from the device without further action.
Because the communication from this point on is
entirely one-sided coming from the device. There is
nothing we can do from this end if a message fails to
arrive, so we keep the network as quiet as possible
by doubling the timeout.
"""
super().__init__(on_done, num_retry)
super().__init__(on_done, num_retry, time_out)
self.db = device_db

#-----------------------------------------------------------------------
Expand Down Expand Up @@ -83,6 +96,10 @@ def msg_received(self, protocol, msg):

if msg.flags.type == Msg.Flags.Type.DIRECT_ACK:
LOG.info("%s device ACK response", msg.from_addr)
# From here on out, the device is the only one talking. So
# remove any remaining retries, and double the timeout.
self._num_retry = 0
self._time_out = 2 * self._time_out
return Msg.CONTINUE

elif msg.flags.type == Msg.Flags.Type.DIRECT_NAK:
Expand Down
4 changes: 2 additions & 2 deletions insteon_mqtt/handler/DeviceDbModify.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DeviceDbModify(Base):
modifications to the device's all link database class to reflect what
happened on the physical device.
"""
def __init__(self, device_db, entry, on_done=None):
def __init__(self, device_db, entry, on_done=None, num_retry=3):
"""Constructor
Args:
Expand All @@ -29,7 +29,7 @@ def __init__(self, device_db, entry, on_done=None):
added to the handler. Signature is:
on_done(success, msg, entry)
"""
super().__init__(on_done)
super().__init__(on_done, num_retry)

self.db = device_db
self.entry = entry
Expand Down

0 comments on commit e036b3d

Please sign in to comment.