eliminiated redunant call and tuned connection timing
This commit is contained in:
parent
309fc7e3c5
commit
5ba5765435
1 changed files with 6 additions and 6 deletions
|
@ -17,6 +17,7 @@ class ChannelMonitor(threading.Thread):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
threading.Thread.__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_url = app.config['MATRIX_HOST'] + '/_matrix/client/r0'
|
||||||
self.matrix_api_token = app.config['MATRIX_AS_TOKEN']
|
self.matrix_api_token = app.config['MATRIX_AS_TOKEN']
|
||||||
self.txId = 0
|
self.txId = 0
|
||||||
|
@ -108,9 +109,8 @@ class ChannelMonitor(threading.Thread):
|
||||||
|
|
||||||
def poll_channel(self, room):
|
def poll_channel(self, room):
|
||||||
try:
|
try:
|
||||||
r = Pnut(app.config['MATRIX_PNUT_TOKEN']).get_channel_stream(room.pnut_chan, room.pnut_since)
|
r = self.pnut.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'])
|
||||||
print(r.headers['X-RateLimit-Remaining'], r.headers['X-RateLimit-Reset'])
|
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
logging.info('*** Problem connecting to pnut.io! Waiting to retry. ***')
|
logging.info('*** Problem connecting to pnut.io! Waiting to retry. ***')
|
||||||
time.sleep(30)
|
time.sleep(30)
|
||||||
|
@ -189,8 +189,8 @@ class ChannelMonitor(threading.Thread):
|
||||||
rooms = MatrixRoom2.query.all()
|
rooms = MatrixRoom2.query.all()
|
||||||
for r in rooms:
|
for r in rooms:
|
||||||
self.poll_channel(r)
|
self.poll_channel(r)
|
||||||
time.sleep(1)
|
time.sleep(.25)
|
||||||
time.sleep(1.5)
|
time.sleep(3)
|
||||||
logging.info("-- Stopping channel monitor --")
|
logging.info("-- Stopping channel monitor --")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -207,4 +207,4 @@ if __name__ == '__main__':
|
||||||
app.run(port=config['LISTEN_PORT'])
|
app.run(port=config['LISTEN_PORT'])
|
||||||
|
|
||||||
_shutdown.set()
|
_shutdown.set()
|
||||||
logging.info("-- Shutdown in progress --")
|
logging.info("-- Shutdown in progress --")
|
||||||
|
|
Loading…
Reference in a new issue