add retry to feeder
This commit is contained in:
parent
d348bee04f
commit
85636814ed
|
@ -1,4 +1,5 @@
|
||||||
.idea
|
.idea
|
||||||
|
test.sh
|
||||||
|
|
||||||
# ---> Python
|
# ---> Python
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
|
|
|
@ -43,12 +43,17 @@ client.loop_start()
|
||||||
|
|
||||||
def publish(topic: str, msg):
|
def publish(topic: str, msg):
|
||||||
topic_expanded = MQTT_TOPIC_PREFIX + '/' + topic
|
topic_expanded = MQTT_TOPIC_PREFIX + '/' + topic
|
||||||
result = client.publish(topic_expanded, msg)
|
retries = 10
|
||||||
status = result[0]
|
for i in range(retries): # retry
|
||||||
if status == 0:
|
result = client.publish(topic_expanded, msg)
|
||||||
logging.info(f"Sent {msg} to topic {topic_expanded}")
|
status = result[0]
|
||||||
else:
|
if status == 0:
|
||||||
logging.error(f"Failed to send message to topic {topic_expanded}: {result}")
|
logging.info(f"Sent {msg} to topic {topic_expanded}")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
logging.warning(f"Failed to send message to topic {topic_expanded}: {result}. Retry {i + 1}/{retries}")
|
||||||
|
time.sleep(10)
|
||||||
|
logging.error(f"Failed to send message to topic {topic_expanded}.")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in New Issue