Skip to content

Commit

Permalink
Merge pull request #77 from adsabs/sort
Browse files Browse the repository at this point in the history
changing logs
  • Loading branch information
femalves authored Oct 1, 2024
2 parents 8deffbc + 4b11bfd commit f8916f7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions alembic/versions/21bf40903ec3_update_json_queries_with_bibcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
from alembic import op
import sqlalchemy as sa
import json
from flask import current_app
import logging
import sys

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler(sys.stdout))

def update_queries(main_session):
sql_query = """
Expand All @@ -39,7 +43,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 +74,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 +99,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 f8916f7

Please sign in to comment.