Skip to content

Commit

Permalink
changing logs
Browse files Browse the repository at this point in the history
  • Loading branch information
femalves committed Aug 28, 2024
1 parent d033550 commit 2ff1d9c
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
from alembic import op
import sqlalchemy as sa
import json
from flask import current_app
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

def update_queries(main_session):
sql_query = """
Expand All @@ -39,7 +41,7 @@ def update_queries(main_session):
FROM filtered_queries
"""

current_app.logger.info('Getting records...')
logger.info('Getting records...')
result = main_session.execute(sa.text(sql_query))
records = result.fetchall()

Expand Down Expand Up @@ -70,22 +72,22 @@ def update_queries(main_session):
'query': json.dumps(saved_queries).encode('utf-8')
})

current_app.logger.info('Records to update: {}'.format(len(update_queries)))
logger.info('Records to update: {}'.format(len(update_queries)))
try:
for item in update_queries:
update_sql = sa.text("""
UPDATE public.queries
SET query = :query
WHERE id = :id
""")
current_app.logger.info('Updating record with id: {}'.format(item['id']))
logger.info('Updating record with id: {}'.format(item['id']))
main_session.execute(update_sql, {'query': item['query'], 'id': item['id']})

current_app.logger.info('Total records updated: {}'.format(len(update_queries)))
logger.info('Total records updated: {}'.format(len(update_queries)))
main_session.commit()
except Exception as e:
main_session.rollback()
current_app.logger.error('Error occurred during update: {}'.format(str(e)))
logger.error('Error occurred during update: {}'.format(str(e)))
raise
finally:
main_session.close()
Expand All @@ -95,7 +97,7 @@ def upgrade():
try:
update_queries(session)
except Exception as e:
current_app.logger.error('Upgrade failed: {}'.format(str(e)))
logger.error('Upgrade failed: {}'.format(str(e)))

def downgrade():
pass

0 comments on commit 2ff1d9c

Please sign in to comment.