Skip to content

Commit 191adf0

Browse files
Merge pull request #183 from OpenUpSA/indexing
added jobs monitor
2 parents d029255 + fd16cc3 commit 191adf0

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

app.py

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,20 @@ def delete(self, pathogen_id):
341341

342342
with get_db_cursor() as cursor:
343343
if hard_delete:
344+
345+
# Check if there are associated schemas
346+
cursor.execute("""
347+
SELECT COUNT(*) as count FROM schemas
348+
WHERE pathogen_id = %s
349+
""", (pathogen_id,))
350+
351+
schema_count = cursor.fetchone()['count']
352+
353+
if schema_count > 0:
354+
return {
355+
'error': f'Cannot delete pathogen: {schema_count} schema(s) are still associated with it. Delete schemas first or use soft delete.'
356+
}, 400
357+
344358
# Hard delete - permanently remove from database
345359
cursor.execute("""
346360
DELETE FROM pathogens
@@ -2672,11 +2686,6 @@ def post(self):
26722686
try:
26732687
data = request.get_json()
26742688

2675-
print('========================================')
2676-
print("Incoming search query:")
2677-
print(data)
2678-
print('========================================')
2679-
26802689
# convert json data to string and replace all .keyword with ''
26812690
data_str = json.dumps(data).replace('.keyword', '')
26822691
data = json.loads(data_str)
@@ -2731,10 +2740,6 @@ def post(self):
27312740
if not data:
27322741
return {'error': 'No JSON data provided'}, 400
27332742

2734-
print("Final Query ========================")
2735-
print(data['query'])
2736-
print("===================================")
2737-
27382743
results = query_elastic(data)
27392744

27402745
print(results)
@@ -2830,6 +2835,41 @@ def post(self):
28302835
logger.exception(f"Error during reindexing: {str(e)}")
28312836
return {'error': f'Reindexing error: {str(e)}'}, 500
28322837

2838+
##########################
2839+
### JOBS MONITORING
2840+
##########################
2841+
2842+
jobs_ns = api.namespace('jobs', description='Job monitoring endpoints')
2843+
2844+
@jobs_ns.route('/')
2845+
class JobsList(Resource):
2846+
2847+
### GET /jobs ###
2848+
2849+
@jobs_ns.doc('list_jobs')
2850+
@require_auth(keycloak_auth)
2851+
@require_permission('system_admin_access')
2852+
def get(self):
2853+
"""List all jobs from the jobs table"""
2854+
2855+
try:
2856+
with get_db_cursor() as cursor:
2857+
cursor.execute("""
2858+
SELECT * FROM jobs
2859+
ORDER BY created_at DESC
2860+
""")
2861+
2862+
jobs = cursor.fetchall()
2863+
2864+
return {
2865+
'jobs': jobs,
2866+
'total': len(jobs)
2867+
}
2868+
2869+
except Exception as e:
2870+
logger.exception(f"Error retrieving jobs: {str(e)}")
2871+
return {'error': f'Database error: {str(e)}'}, 500
2872+
28332873

28342874

28352875
##########################

helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,11 +739,11 @@ async def check_for_sequence_data(isolate, split_on_fasta_headers=True):
739739
"""
740740
SELECT object_id
741741
FROM submission_files
742-
WHERE filename = %s AND file_type = 'fasta'
742+
WHERE filename = %s AND file_type = 'fasta' AND submission_id = %s
743743
ORDER BY created_at DESC
744744
LIMIT 1
745745
""",
746-
(fasta_file,),
746+
(fasta_file, isolate['submission_id']),
747747
)
748748
file_record = cursor.fetchone()
749749

@@ -763,11 +763,11 @@ async def check_for_sequence_data(isolate, split_on_fasta_headers=True):
763763
"""
764764
SELECT object_id
765765
FROM submission_files
766-
WHERE filename = %s AND file_type = 'fasta'
766+
WHERE filename = %s AND file_type = 'fasta' AND submission_id = %s
767767
ORDER BY created_at DESC
768768
LIMIT 1
769769
""",
770-
(fasta_file,),
770+
(fasta_file, isolate['submission_id']),
771771
)
772772
file_record = cursor.fetchone()
773773

0 commit comments

Comments
 (0)