Compare commits

...

2 commits

Author SHA1 Message Date
Egg f4edfba532 add timer for bot crawl that appears in debug log 2024-10-09 16:14:29 +02:00
Egg d7aea928d1 reduce explicit db commits 2024-10-09 16:04:45 +02:00
3 changed files with 7 additions and 6 deletions

View file

@ -5,7 +5,7 @@ from config import config
from db import db
import logging
from sendmail import sendmail
from time import sleep
from time import sleep, time
def shutdown():
try:
@ -34,14 +34,16 @@ if __name__ == '__main__':
while True:
sleep(15) # rest 15 seconds between each crawl run
for user in db.active_users:
sleep(1)
for bot in bots:
timer_crawl = time()
reports = bot.crawl(user)
logger.debug("Crawl using bot %s took %f seconds" % (bot, time()-timer_crawl))
for status in reports:
if not user.is_appropriate(status):
logger.info("Inaproppriate message: %d %s %s" % (user.uid, status.author, status.text))
continue
for bot2 in bots:
sleep(1)
bot2.post(user, status)
logger.info("Resent: %d %s %s" % (user.uid, status.author, status.text))
except Exception:

4
db.py
View file

@ -27,13 +27,15 @@ class DB(object):
break
except sqlite3.OperationalError as error:
# another thread may be writing, give it a chance to finish
sleep(0.5)
sleep(1)
logger.exception()
if time() - start_time > 5:
# if it takes this long, something is wrong
system("rcctl restart frontend_daemon")
logger.warning("frontend_daemon is getting restarted")
self.conn.commit()
elif time() - start_time > 10:
return
def close(self):
self.conn.close()

View file

@ -158,7 +158,6 @@ schlitz
def toot_witness(self, toot_uri):
db.execute("INSERT INTO seen_toots (toot_uri, user_id) VALUES (?,?);",
(toot_uri, self.uid))
db.commit()
def get_seen_tg(self):
db.execute("SELECT tg_id FROM seen_telegrams WHERE user_id = ?;",
@ -168,7 +167,6 @@ schlitz
def save_seen_tg(self, tg_id):
db.execute("UPDATE seen_telegrams SET tg_id = ? WHERE user_id = ?;",
(tg_id, self.uid))
db.commit()
def get_mailinglist(self):
db.execute("SELECT email FROM mailinglist WHERE user_id = ?;", (self.uid, ))
@ -181,7 +179,6 @@ schlitz
def save_seen_mail(self, mail_date):
db.execute("UPDATE seen_mail SET mail_date = ? WHERE user_id = ?;",
(mail_date, self.uid))
db.commit()
def set_trigger_words(self, patterns):
db.execute("UPDATE triggerpatterns SET patterns = ? WHERE user_id = ?;",