improve sleep. add error logging to db
parent
8784a0abf0
commit
d584cb7d79
|
@ -89,7 +89,7 @@ class TelegramBot(Bot):
|
||||||
try:
|
try:
|
||||||
for subscriber_id in user.get_telegram_subscribers():
|
for subscriber_id in user.get_telegram_subscribers():
|
||||||
tb.send_message(subscriber_id, text).wait()
|
tb.send_message(subscriber_id, text).wait()
|
||||||
sleep(0.1)
|
sleep(0.5)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error('Error telegramming: ' + user.get_city() + ': '
|
logger.error('Error telegramming: ' + user.get_city() + ': '
|
||||||
+ str(report.id), exc_info=True)
|
+ str(report.id), exc_info=True)
|
||||||
|
|
|
@ -34,15 +34,14 @@ if __name__ == '__main__':
|
||||||
while True:
|
while True:
|
||||||
for user in db.active_users:
|
for user in db.active_users:
|
||||||
for bot in bots:
|
for bot in bots:
|
||||||
sleep(0.1)
|
sleep(5)
|
||||||
reports = bot.crawl(user)
|
reports = bot.crawl(user)
|
||||||
for status in reports:
|
for status in reports:
|
||||||
sleep(0.1)
|
|
||||||
if not user.is_appropriate(status):
|
if not user.is_appropriate(status):
|
||||||
logger.info("Inaproppriate message: %d %s %s" % (user.uid, status.author, status.text))
|
logger.info("Inaproppriate message: %d %s %s" % (user.uid, status.author, status.text))
|
||||||
continue
|
continue
|
||||||
for bot2 in bots:
|
for bot2 in bots:
|
||||||
sleep(0.1)
|
sleep(1)
|
||||||
bot2.post(user, status)
|
bot2.post(user, status)
|
||||||
logger.info("Resent: %d %s %s" % (user.uid, status.author, status.text))
|
logger.info("Resent: %d %s %s" % (user.uid, status.author, status.text))
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
6
db.py
6
db.py
|
@ -25,12 +25,14 @@ class DB(object):
|
||||||
try:
|
try:
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
break
|
break
|
||||||
except sqlite3.OperationalError:
|
except sqlite3.OperationalError as error:
|
||||||
# another thread may be writing, give it a chance to finish
|
# another thread may be writing, give it a chance to finish
|
||||||
sleep(0.1)
|
sleep(0.5)
|
||||||
|
logger.exception()
|
||||||
if time() - start_time > 5:
|
if time() - start_time > 5:
|
||||||
# if it takes this long, something is wrong
|
# if it takes this long, something is wrong
|
||||||
system("rcctl restart frontend_daemon")
|
system("rcctl restart frontend_daemon")
|
||||||
|
logger.warning("frontend_daemon is getting restarted")
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|
Loading…
Reference in New Issue