-
Notifications
You must be signed in to change notification settings - Fork 1
/
cleanup.py
30 lines (23 loc) · 926 Bytes
/
cleanup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from app.conf import Config
from app.logging import Logging
from app.db import DbConnectionPool
from app.ratelimit import Ratelimit
from app.message import Message
class Cleaner:
def __init__(self, conf: object = None) -> None:
self.conf = conf or Config()
self.logger = Logging.get_logger(self.conf)
self.db_pool = DbConnectionPool(self.conf)
self.logger.debug('Cleaning up database')
self.reset_counters()
self.cleanup()
def reset_counters(self) -> None:
"""Reset counters"""
Ratelimit.reset_all_counters(self.db_pool, self.logger)
def cleanup(self) -> None:
"""Cleanup database"""
message_retention = int(self.conf.get('MESSAGE_RETENTION', 0))
if message_retention > 0:
Message.purge_old_messages(self.db_pool, self.logger, message_retention)
if __name__ == '__main__': # pragma: no cover
Cleaner()