-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger_reanalysis.py
More file actions
69 lines (52 loc) · 2 KB
/
Copy pathtrigger_reanalysis.py
File metadata and controls
69 lines (52 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sys
import os
import time
import uuid
import json
sys.path.append(os.path.join(os.getcwd(), "backend"))
from app.database import SessionLocal, DatabaseOperations, SampleStatus, AnalysisStatus
from app.tasks.orchestration import analyze_sample
SAMPLE_ID = "ed8ee6ac-ed52-47a2-a718-049f04bc9ff5"
def trigger_reanalysis():
db = SessionLocal()
try:
sample_uuid = uuid.UUID(SAMPLE_ID)
sample = DatabaseOperations.get_sample_by_id(db, sample_uuid)
if not sample:
print(f"Sample {SAMPLE_ID} not found!")
return
print(
f"Triggering re-analysis for sample: {sample.original_filename} ({sample.id})"
)
sample.status = SampleStatus.ANALYZING
for result in sample.analysis_results:
result.status = AnalysisStatus.RUNNING
result.results_json = None
result.error_message = None
db.commit()
task = analyze_sample.apply_async(args=[SAMPLE_ID])
print(f"Task submitted. Task ID: {task.id}")
print("Waiting for analysis to complete...")
for i in range(120):
db.refresh(sample)
print(f"Status: {sample.status.value}")
if (
sample.status == SampleStatus.COMPLETED
or sample.status == SampleStatus.FAILED
):
break
time.sleep(2)
print(f"Final Status: {sample.status.value}")
for r in sample.analysis_results:
print(f"Analysis: {r.analysis_type.value}")
print(f"Status: {r.status.value}")
if r.results_json:
print(f"Results keys: {list(r.results_json.keys())}")
if "errors" in r.results_json:
print(f"Errors: {r.results_json['errors']}")
if "behavior_summary" in r.results_json:
print(f"Behavior: {r.results_json['behavior_summary']}")
finally:
db.close()
if __name__ == "__main__":
trigger_reanalysis()