From 5d8cc403dc03db5932f461591766526f14278294 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 25 Jul 2018 02:26:11 +0200 Subject: [PATCH] Handling Adafruit throttling exceptions with a sleep before retrying --- platypush/plugins/adafruit/io.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platypush/plugins/adafruit/io.py b/platypush/plugins/adafruit/io.py index 4658277f19..5df8645927 100644 --- a/platypush/plugins/adafruit/io.py +++ b/platypush/plugins/adafruit/io.py @@ -3,6 +3,7 @@ import time from threading import Thread from Adafruit_IO import Client +from Adafruit_IO.errors import ThrottlingError from platypush.context import get_backend from platypush.message import Message @@ -100,7 +101,11 @@ class AdafruitIoPlugin(Plugin): for (feed, values) in data.items(): if values: - self.send(feed, values, enqueue=False) + try: + self.send(feed, values, enqueue=False) + except ThrottlingError: + self.logger.warning('Adafruit IO throttling threshold hit, taking a nap before retrying') + time.sleep(self.throttle_seconds) data = {}