eliminiated redunant call and tuned connection timing

This commit is contained in:
Morgan McMillian 2017-08-30 13:40:19 -07:00
parent 309fc7e3c5
commit 5ba5765435

View file

@ -17,6 +17,7 @@ class ChannelMonitor(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.pnut = Pnut(app.config['MATRIX_PNUT_TOKEN'])
self.matrix_api_url = app.config['MATRIX_HOST'] + '/_matrix/client/r0'
self.matrix_api_token = app.config['MATRIX_AS_TOKEN']
self.txId = 0
@ -108,9 +109,8 @@ class ChannelMonitor(threading.Thread):
def poll_channel(self, room):
try:
r = Pnut(app.config['MATRIX_PNUT_TOKEN']).get_channel_stream(room.pnut_chan, room.pnut_since)
if r.headers['X-RateLimit-Remaining'] < 40:
print(r.headers['X-RateLimit-Remaining'], r.headers['X-RateLimit-Reset'])
r = self.pnut.get_channel_stream(room.pnut_chan, room.pnut_since)
print(r.headers['X-RateLimit-Remaining'], r.headers['X-RateLimit-Reset'])
except requests.exceptions.ConnectionError:
logging.info('*** Problem connecting to pnut.io! Waiting to retry. ***')
time.sleep(30)
@ -189,8 +189,8 @@ class ChannelMonitor(threading.Thread):
rooms = MatrixRoom2.query.all()
for r in rooms:
self.poll_channel(r)
time.sleep(1)
time.sleep(1.5)
time.sleep(.25)
time.sleep(3)
logging.info("-- Stopping channel monitor --")
if __name__ == '__main__':