Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changing logs #77

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading