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

Fix retry insert data issue #2668

Merged
merged 6 commits into from
Jan 23, 2024
Merged
Changes from 3 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
5 changes: 5 additions & 0 deletions augur/application/db/session.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import os

Check warning on line 1 in augur/application/db/session.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 C0114: Missing module docstring (missing-module-docstring) Raw Output: augur/application/db/session.py:1:0: C0114: Missing module docstring (missing-module-docstring)
import re
import time
import sys
import random
import logging
from sqlalchemy.orm import Session

Check warning on line 7 in augur/application/db/session.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 E0401: Unable to import 'sqlalchemy.orm' (import-error) Raw Output: augur/application/db/session.py:7:0: E0401: Unable to import 'sqlalchemy.orm' (import-error)
from sqlalchemy.dialects import postgresql

Check warning on line 8 in augur/application/db/session.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 E0401: Unable to import 'sqlalchemy.dialects' (import-error) Raw Output: augur/application/db/session.py:8:0: E0401: Unable to import 'sqlalchemy.dialects' (import-error)
from sqlalchemy.exc import OperationalError

Check warning on line 9 in augur/application/db/session.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 E0401: Unable to import 'sqlalchemy.exc' (import-error) Raw Output: augur/application/db/session.py:9:0: E0401: Unable to import 'sqlalchemy.exc' (import-error)

from typing import Optional, List, Union
from psycopg2.errors import DeadlockDetected

Check warning on line 12 in augur/application/db/session.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 E0401: Unable to import 'psycopg2.errors' (import-error) Raw Output: augur/application/db/session.py:12:0: E0401: Unable to import 'psycopg2.errors' (import-error)

# from augur.tasks.util.random_key_auth import RandomKeyAuth
from augur.application.db.engine import EngineConnection
from augur.tasks.util.worker_util import remove_duplicate_dicts, remove_duplicates_by_uniques


def remove_null_characters_from_string(string):

Check warning on line 19 in augur/application/db/session.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 C0116: Missing function or method docstring (missing-function-docstring) Raw Output: augur/application/db/session.py:19:0: C0116: Missing function or method docstring (missing-function-docstring)

if string:
return string.replace("\x00", "\uFFFD")

return string

def remove_null_characters_from_strings_in_dict(data, fields):

Check warning on line 26 in augur/application/db/session.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 C0116: Missing function or method docstring (missing-function-docstring) Raw Output: augur/application/db/session.py:26:0: C0116: Missing function or method docstring (missing-function-docstring)

for field in fields:

Expand All @@ -40,14 +40,14 @@

return data

def remove_null_characters_from_list_of_dicts(data_list, fields):

Check warning on line 43 in augur/application/db/session.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 C0116: Missing function or method docstring (missing-function-docstring) Raw Output: augur/application/db/session.py:43:0: C0116: Missing function or method docstring (missing-function-docstring)

for value in data_list:
value = remove_null_characters_from_strings_in_dict(value, fields)

return data_list

class DatabaseSession(Session):

Check warning on line 50 in augur/application/db/session.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 C0115: Missing class docstring (missing-class-docstring) Raw Output: augur/application/db/session.py:50:0: C0115: Missing class docstring (missing-class-docstring)

def __init__(self, logger, engine=None, from_msg=None, **kwargs):

Expand All @@ -58,7 +58,7 @@

if self.engine is None:
self.logger.debug("Passing engine will be required soon")
from augur.application.db.engine import DatabaseEngine

Check warning on line 61 in augur/application/db/session.py

View workflow job for this annotation

GitHub Actions / runner / pylint

[pylint] reported by reviewdog 🐶 C0415: Import outside toplevel (augur.application.db.engine.DatabaseEngine) (import-outside-toplevel) Raw Output: augur/application/db/session.py:61:12: C0415: Import outside toplevel (augur.application.db.engine.DatabaseEngine) (import-outside-toplevel)

self.engine_created = True

Expand Down Expand Up @@ -197,6 +197,7 @@
if(len(data) == 1):
ABrain7710 marked this conversation as resolved.
Show resolved Hide resolved
ABrain7710 marked this conversation as resolved.
Show resolved Hide resolved
raise e
else:
time.sleep(5)
first_half = data[:len(data)//2]
second_half = data[len(data)//2:]

Expand Down Expand Up @@ -234,12 +235,16 @@
if(len(data) == 1):
ABrain7710 marked this conversation as resolved.
Show resolved Hide resolved
ABrain7710 marked this conversation as resolved.
Show resolved Hide resolved
raise e
else:
time.sp
ABrain7710 marked this conversation as resolved.
Show resolved Hide resolved
first_half = data[:len(data)//2]
second_half = data[len(data)//2:]

self.insert_data(first_half, natural_keys, return_columns, string_fields, on_conflict_update)
self.insert_data(second_half, natural_keys, return_columns, string_fields, on_conflict_update)

self.insert_data(first_half, table, natural_keys, return_columns, string_fields, on_conflict_update)
self.insert_data(second_half, table, natural_keys, return_columns, string_fields, on_conflict_update)

else:
self.logger.error("Unable to insert and return data in 10 attempts")
return None
Expand Down
Loading