diff options
author | Frederick Muriuki Muriithi | 2023-06-02 14:14:14 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-06-02 14:16:11 +0300 |
commit | c25b148eabdd836920614eacfe345af9ea1d2fe7 (patch) | |
tree | 48eef1269e37abc3c169f309676163164f68a68d | |
parent | f0763bc2e0b65796d28b737f72f97c53602e1468 (diff) | |
download | genenetwork3-c25b148eabdd836920614eacfe345af9ea1d2fe7.tar.gz |
auth: Add delay between DB inserts
Add delays to avoid overwhelming the DB server.
-rw-r--r-- | scripts/migrate_existing_data.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/scripts/migrate_existing_data.py b/scripts/migrate_existing_data.py index 0741940..0dfc89a 100644 --- a/scripts/migrate_existing_data.py +++ b/scripts/migrate_existing_data.py @@ -4,6 +4,8 @@ group for accessibility purposes. """ import sys import json +import time +import random from pathlib import Path from uuid import UUID, uuid4 @@ -148,6 +150,10 @@ def default_resources(conn: authdb.DbConnection, group: Group) -> tuple[ tuple() ) for row in rows) +def delay(): + """Delay a while: anything from 2 seconds to 15 seconds.""" + time.sleep(random.choice(range(2,16))) + def __assigned_mrna__(authconn): """Retrieve assigned mRNA items.""" with authdb.cursor(authconn) as cursor: @@ -205,6 +211,7 @@ def __assign_mrna__(authconn, bioconn, resource): "(:group_id, :resource_id, :data_link_id)", unassigned) print(f"-> mRNA: Linked {len(unassigned)}") + delay() def __assigned_geno__(authconn): """Retrieve assigned genotype data.""" @@ -262,6 +269,7 @@ def __assign_geno__(authconn, bioconn, resource): "(:group_id, :resource_id, :data_link_id)", unassigned) print(f"-> Genotype: Linked {len(unassigned)}") + delay() def __assigned_pheno__(authconn): """Retrieve assigned phenotype data.""" @@ -325,6 +333,7 @@ def __assign_pheno__(authconn, bioconn, resource): "(:group_id, :resource_id, :data_link_id)", unassigned) print(f"-> Phenotype: Linked {len(unassigned)}") + delay() def assign_data_to_resource(authconn, bioconn, resource: Resource): """Assign existing data, not linked to any group to the resource.""" |