aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-06-02 14:14:14 +0300
committerFrederick Muriuki Muriithi2023-06-02 14:16:11 +0300
commitc25b148eabdd836920614eacfe345af9ea1d2fe7 (patch)
tree48eef1269e37abc3c169f309676163164f68a68d /scripts
parentf0763bc2e0b65796d28b737f72f97c53602e1468 (diff)
downloadgenenetwork3-c25b148eabdd836920614eacfe345af9ea1d2fe7.tar.gz
auth: Add delay between DB inserts
Add delays to avoid overwhelming the DB server.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/migrate_existing_data.py9
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."""