Handling Adafruit throttling exceptions with a sleep before retrying

This commit is contained in:
Fabio Manganiello 2018-07-25 02:26:11 +02:00
parent b777bbcfa8
commit 5d8cc403dc

View file

@ -3,6 +3,7 @@ import time
from threading import Thread from threading import Thread
from Adafruit_IO import Client from Adafruit_IO import Client
from Adafruit_IO.errors import ThrottlingError
from platypush.context import get_backend from platypush.context import get_backend
from platypush.message import Message from platypush.message import Message
@ -100,7 +101,11 @@ class AdafruitIoPlugin(Plugin):
for (feed, values) in data.items(): for (feed, values) in data.items():
if values: if values:
try:
self.send(feed, values, enqueue=False) 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 = {} data = {}