Skip to content

Commit 4290e9e

Browse files
committed
checks database status before starting the run - disables the start button until the database is present
1 parent 3ff1860 commit 4290e9e

3 files changed

Lines changed: 61 additions & 5 deletions

File tree

frontend/src/modules/analysis/analysis-data/analysis-data.component.tsx

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IAnalysisDataProps } from "./analysis-data.interfaces";
33
import { socket } from "../../../app.component";
44
import { Chart } from "react-google-charts";
55
import axios from "axios";
6-
import { Dropdown, Modal, Button } from "react-bootstrap";
6+
import { Dropdown, Modal, Button, OverlayTrigger, Tooltip } from "react-bootstrap";
77
import './analysis-data.component.css';
88

99
const POLLING_INTERVAL_MS = 10000;
@@ -19,6 +19,7 @@ const AnalysisDataComponent: FunctionComponent<IAnalysisDataProps> = ({ data })
1919
const [showConfirmModal, setShowConfirmModal] = useState(false);
2020
type TimeUnit = 'seconds' | 'minutes' | 'hours' | 'days';
2121
const [timeUnit, setTimeUnit] = useState<TimeUnit>('seconds');
22+
const [isDatabaseReady, setIsDatabaseReady] = useState(false);
2223

2324
const threshold = data.data.queries[0]?.threshold ? parseFloat(data.data.queries[0].threshold) : 100;
2425

@@ -29,6 +30,18 @@ const AnalysisDataComponent: FunctionComponent<IAnalysisDataProps> = ({ data })
2930
days: 'd'
3031
};
3132

33+
const checkDatabaseStatus = async (projectId: string) => {
34+
try {
35+
const res = await axios.get(`http://localhost:5007/check_database_status?projectId=${projectId}`);
36+
console.log("Database status response:", res.data);
37+
return res.data.is_ready;
38+
} catch (error) {
39+
console.error("Error checking database status:", error);
40+
return false; // Assume not ready if there's an error
41+
}
42+
};
43+
44+
3245
useEffect(() => {
3346
socket.emit('check_fastq_file_listener', { projectId: analysisData.data.projectId });
3447

@@ -89,6 +102,14 @@ const AnalysisDataComponent: FunctionComponent<IAnalysisDataProps> = ({ data })
89102
setError("Failed to connect to the server. Please check your network connection.");
90103
}
91104
}
105+
106+
// Check database status
107+
const checkStats = await checkDatabaseStatus(analysisData.data.projectId);
108+
setIsDatabaseReady(checkStats);
109+
if (!checkStats) {
110+
setError("Database is not ready. Please wait for the database to be initialized.");
111+
}
112+
92113
};
93114

94115
fetchData();
@@ -237,11 +258,24 @@ const AnalysisDataComponent: FunctionComponent<IAnalysisDataProps> = ({ data })
237258
<i className="fas fa-stop"></i> Stop Analysis
238259
</button>
239260
) : (
240-
<button className="btn btn-primary nano-btn" onClick={handleStartFileListener}>
241-
<i className="fas fa-play"></i> Start Analysis
242-
</button>
261+
isDatabaseReady ? (
262+
<button className="btn btn-outline-primary nano-btn" onClick={handleStartFileListener}>
263+
<i className="fas fa-play"></i> Start Analysis
264+
</button>
265+
) : (
266+
<OverlayTrigger
267+
placement="top"
268+
overlay={<Tooltip id="database-not-found-tooltip">Database not found</Tooltip>}
269+
>
270+
<span>
271+
<button className="btn btn-outline-primary nano-btn" disabled>
272+
<i className="fas fa-play"></i> Start Analysis
273+
</button>
274+
</span>
275+
</OverlayTrigger>
276+
)
243277
)}
244-
<button className="btn btn-outline-danger nano-btn" onClick={handleRemoveAnalysis}>
278+
<button className="btn btn-outline-danger" onClick={handleRemoveAnalysis}>
245279
<i className="fas fa-trash"></i> Remove Analysis
246280
</button>
247281
</div>

frontend/src/styles/theme.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ a:hover {
183183
background-color: var(--ont-primary);
184184
}
185185

186+
.btn-outline-danger {
187+
color: var(--ont-danger);
188+
background-color: transparent;
189+
border-color: var(--ont-danger);
190+
}
191+
192+
.btn-outline-danger:hover, .btn-outline-danger:focus {
193+
color: var(--ont-white);
194+
background-color: var(--ont-danger);
195+
}
196+
186197
/* Card Styles */
187198
.card {
188199
position: relative;

server/app/main/routes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import string
77
import uuid
88
import subprocess
9+
import glob
910

1011
from flask import session, render_template, request, abort, jsonify
1112
from . import main
@@ -20,6 +21,16 @@
2021
def version():
2122
return json.dumps({"version": "v0.0.2", "name": "nanocas PoC"})
2223

24+
@main.route('/check_database_status', methods=['GET'])
25+
def check_database_status():
26+
project_id = request.args.get('projectId')
27+
if not project_id:
28+
return jsonify({'error': 'projectId is required'}), 400
29+
nanocas_path = os.path.join(NANOCAS_DIR, project_id)
30+
mmi_files = glob.glob(os.path.join(nanocas_path, 'database', '*.mmi'))
31+
is_ready = len(mmi_files) > 0
32+
return jsonify({'is_ready': is_ready})
33+
2334
@main.route('/get_timeline_info', methods=["GET"])
2435
def get_timeline_info():
2536
timeline_path = get_analysis_timeline_path()

0 commit comments

Comments
 (0)