CLI - add command to clean blacklisted tokens

This commit is contained in:
Sam
2022-09-15 13:14:55 +02:00
parent e39fc3d211
commit 9b377c08e4
11 changed files with 161 additions and 18 deletions

View File

@ -1,13 +1,9 @@
import time
from fittrackee import db
from fittrackee.utils import clean
def clean_tokens(days: int) -> int:
limit = int(time.time()) - (days * 86400)
sql = """
DELETE FROM oauth2_token
WHERE oauth2_token.issued_at + oauth2_token.expires_in < %(limit)s;
"""
result = db.engine.execute(sql, {'limit': limit})
return result.rowcount
return clean(sql, days)

View File

@ -7,7 +7,7 @@ from fittrackee.cli.app import app
from .clean import clean_tokens
handler = logging.StreamHandler()
logger = logging.getLogger('fittrackee_clean_tokens')
logger = logging.getLogger('fittrackee_clean_oauth2_tokens')
logger.setLevel(logging.INFO)
logger.addHandler(handler)