add more info to sync history

This commit is contained in:
Cyberes 2024-03-06 00:18:41 -07:00
parent c3e6e68bb6
commit 5870303c74
2 changed files with 6 additions and 6 deletions

View File

@ -30,7 +30,7 @@ class EmailDatabase:
self.conn = sqlite3.connect(filepath) self.conn = sqlite3.connect(filepath)
cursor = self.conn.cursor() cursor = self.conn.cursor()
cursor.execute(f'CREATE TABLE IF NOT EXISTS folders_mapping (name TEXT UNIQUE, table_name TEXT UNIQUE)') cursor.execute(f'CREATE TABLE IF NOT EXISTS folders_mapping (name TEXT UNIQUE, table_name TEXT UNIQUE)')
cursor.execute(f'CREATE TABLE IF NOT EXISTS syncs (timestamp INTEGER UNIQUE, type TEXT)') cursor.execute(f'CREATE TABLE IF NOT EXISTS syncs (timestamp INTEGER UNIQUE, type TEXT, new_emails INTEGER, new_attachments INTEGER, new_folders INTEGER, duration INTEGER)')
self.conn.commit() self.conn.commit()
cursor.close() cursor.close()
@ -64,10 +64,10 @@ class EmailDatabase:
cursor.close() cursor.close()
return new_email return new_email
def finish_sync(self, sync_type: str): def finish_sync(self, sync_type: str, new_emails: int, new_attachments: int, duration: int):
now = int(time.time()) now = int(time.time())
cursor = self.conn.cursor() cursor = self.conn.cursor()
cursor.execute('INSERT INTO syncs (timestamp, type) VALUES (?, ?)', (now, sync_type)) cursor.execute('INSERT INTO syncs (timestamp, type, new_emails, new_attachments, duration) VALUES (?, ?, ?, ?, ?)', (now, sync_type, new_emails, new_attachments, duration))
self.conn.commit() self.conn.commit()
cursor.close() cursor.close()
return now return now

6
run.py
View File

@ -68,10 +68,10 @@ def main(args):
if len(attachments): if len(attachments):
new_attachments += 1 new_attachments += 1
database.finish_sync('refresh' if not did_full_sync else 'full')
elapsed = datetime.now() - sync_start_time elapsed = datetime.now() - sync_start_time
logger.info(f'Finished email {"refresh" if not did_full_sync else "sync"} in {humanize.naturaldelta(elapsed)} and added {new_emails} new emails.') database.finish_sync('refresh' if not did_full_sync else 'full', new_emails, new_attachments, int(elapsed.total_seconds()))
logger.info(f'Finished email {"refresh" if not did_full_sync else "sync"} in {humanize.naturaldelta(elapsed)} and added {new_emails} new emails and {new_attachments} attachments.')
if __name__ == '__main__': if __name__ == '__main__':