feat: Add remover for old tasks
This commit is contained in:
29
remove_old_tasks.py
Normal file
29
remove_old_tasks.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
from src.db import AnalyzeTask, TaskStatus, DBSession
|
||||
from src.settings import MESSAGE_TTL, init_logging
|
||||
|
||||
|
||||
REMOVE_MULTIPLIER = 3
|
||||
|
||||
|
||||
def main():
|
||||
session = DBSession()
|
||||
count = (
|
||||
session.query(AnalyzeTask)
|
||||
.filter(
|
||||
AnalyzeTask.status == TaskStatus.InQueue,
|
||||
AnalyzeTask.created_at + REMOVE_MULTIPLIER * MESSAGE_TTL
|
||||
< datetime.datetime.now().timestamp(),
|
||||
)
|
||||
.delete()
|
||||
)
|
||||
session.commit()
|
||||
session.close()
|
||||
logging.info(f"deleted {count} old in_queue tasks")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
init_logging()
|
||||
main()
|
||||
Reference in New Issue
Block a user