|
| 1 | +# Generated manually by the seqr team |
| 2 | +import math |
| 3 | + |
| 4 | +from django.db import migrations |
| 5 | +import requests |
| 6 | + |
| 7 | +from settings import PIPELINE_RUNNER_SERVER |
| 8 | + |
| 9 | + |
| 10 | +def batch_project_guids(project_guids, max_batches=30, min_batch_size=5): |
| 11 | + n = len(project_guids) |
| 12 | + if n == 0: |
| 13 | + return [] |
| 14 | + batch_size = max(math.ceil(n / max_batches), min_batch_size) |
| 15 | + return [project_guids[i : i + batch_size] for i in range(0, n, batch_size)] |
| 16 | + |
| 17 | + |
| 18 | +def queue_rebuild_gt_stats_jobs(apps, schema_editor): |
| 19 | + ProjectGtStatsGRCh37SnvIndel = apps.get_model( |
| 20 | + "clickhouse_search", "ProjectGtStatsGRCh37SnvIndel" |
| 21 | + ) |
| 22 | + ProjectGtStatsSnvIndel = apps.get_model( |
| 23 | + "clickhouse_search", "ProjectGtStatsSnvIndel" |
| 24 | + ) |
| 25 | + db_alias = schema_editor.connection.alias |
| 26 | + for batch in batch_project_guids( |
| 27 | + list( |
| 28 | + set( |
| 29 | + ProjectGtStatsGRCh37SnvIndel.objects.using(db_alias) |
| 30 | + .values_list("project_guid", flat=True) |
| 31 | + .distinct() |
| 32 | + ) |
| 33 | + | set( |
| 34 | + ProjectGtStatsSnvIndel.objects.using(db_alias) |
| 35 | + .values_list("project_guid", flat=True) |
| 36 | + .distinct() |
| 37 | + ) |
| 38 | + ) |
| 39 | + ): |
| 40 | + response = requests.post( |
| 41 | + f"{PIPELINE_RUNNER_SERVER}/rebuild_gt_stats_enqueue", |
| 42 | + json={"project_guids": batch}, |
| 43 | + timeout=60, |
| 44 | + ) |
| 45 | + response.raise_for_status() |
| 46 | + print(f"Triggered rebuild_gt_stats_enqueue for {batch}") |
| 47 | + |
| 48 | + |
| 49 | +class Migration(migrations.Migration): |
| 50 | + dependencies = [ |
| 51 | + ("clickhouse_search", "0017_fix_affected_status_column_order"), |
| 52 | + ] |
| 53 | + |
| 54 | + operations = [ |
| 55 | + migrations.RunPython(queue_rebuild_gt_stats_jobs), |
| 56 | + ] |
0 commit comments