Skip to content

Commit

Permalink
cleanup fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-stanek committed Apr 21, 2024
1 parent bd18cb4 commit a09df55
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import date, timedelta

import click
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
from sqlalchemy import text

from app import app, db
from app.etl import MetricsEtl
Expand Down Expand Up @@ -92,15 +92,13 @@ def clean_db_command():
"""Deletes older partition than 14 days. Executed weekly via cron"""
eng = db.engine

eng.execute(
"DELETE FROM ockovani_registrace WHERE import_id<(SELECT min(id) FROM importy WHERE start>now()-'14 days'::interval)")
with eng.connect() as conn:
conn.execute(text("DELETE FROM ockovani_registrace WHERE import_id<(SELECT min(id) FROM importy WHERE start>now()-'14 days'::interval)"))
app.logger.info("Old data deleted.")

connection = eng.raw_connection()
connection.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
cursor = connection.cursor()
cursor.execute("VACUUM(FULL, ANALYZE) ockovani_registrace")
with eng.connect() as conn:
with conn.execution_options(isolation_level='AUTOCOMMIT'):
conn.execute(text("VACUUM(FULL, ANALYZE) ockovani_registrace"))
app.logger.info("Vacuum finished.")
connection.autocommit = False

exit(0)
2 changes: 1 addition & 1 deletion scripts/cron
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
# monthly fetcher
00 5 5 * * bash /home/ockovani/prd/app/scripts/execute_action.sh 16635318
# update GP page
*/5 * * * * bash /home/ockovani/prd/app/scripts/execute_action.sh TODO
1/5 * * * * bash /home/ockovani/prd/app/scripts/execute_action.sh TODO
# post tweet - disabled
# 35 7 * * * bash /home/ockovani/prd/app/scripts/execute_action.sh 6797956

0 comments on commit a09df55

Please sign in to comment.