@@ -59,8 +59,11 @@ def list_current_files():
59
59
@jwt_ops .admin_required
60
60
def execute ():
61
61
current_app .logger .info ("Execute flow" )
62
- flow_script .start_flow ()
62
+ job_outcome = flow_script .start_flow () # 'busy', 'completed', or 'nothing to do'
63
+ current_app .logger .info ("Job outcome: " + str (job_outcome ))
63
64
65
+
66
+ # -------- Skip update if 'busy' or 'nothing to do' as nothing changed ? ------
64
67
current_time = datetime .now ().ctime ()
65
68
statistics = get_statistics ()
66
69
@@ -88,8 +91,19 @@ def execute():
88
91
except Exception as e :
89
92
current_app .logger .error ("Insert/Update failed on Last Execution stats" )
90
93
current_app .logger .exception (e )
94
+ # -------------------------------------------------------------------------------
95
+
96
+ if job_outcome == 'busy' :
97
+ return jsonify ({'outcome' : 'Already analyzing' }), 503
98
+
99
+ elif job_outcome == 'nothing to do' :
100
+ return jsonify ({'outcome' : 'No uploaded files to process' }), 200
101
+
102
+ elif job_outcome == 'completed' :
103
+ return jsonify ({'outcome' : 'Analysis completed' }), 200
91
104
92
- return jsonify (success = True )
105
+ else :
106
+ return jsonify ({'outcome' : 'Unknown status: ' + str (job_outcome )}), 200
93
107
94
108
95
109
def get_statistics ():
@@ -157,6 +171,23 @@ def get_exec_status(job_id):
157
171
158
172
return exec_status
159
173
174
+ @admin_api .route ("/api/job_in_progress" , methods = ["GET" ])
175
+ @jwt_ops .admin_required
176
+ def is_job_in_progresss ():
177
+ """Return True if there's a running execute, False if not. """
178
+
179
+ engine .dispose () # we don't want other process's conn pool
180
+
181
+ with engine .connect () as connection :
182
+ q = text ("""SELECT job_id from execution_status WHERE status = 'executing' """ )
183
+ result = connection .execute (q )
184
+
185
+ if result .rowcount > 0 :
186
+ return jsonify (True )
187
+ else :
188
+ return jsonify (False )
189
+
190
+
160
191
def start_job ():
161
192
"""If no running jobs, create a job_id and execution status entry.
162
193
This ensures only only one job runs at a time.
0 commit comments