Skip to content

Commit c6a441e

Browse files
committed
/api/exececute returns outcome. Added /api/job_in_progress
1 parent bbf202f commit c6a441e

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/server/api/admin_api.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ def list_current_files():
5959
@jwt_ops.admin_required
6060
def execute():
6161
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))
6364

65+
66+
# -------- Skip update if 'busy' or 'nothing to do' as nothing changed ? ------
6467
current_time = datetime.now().ctime()
6568
statistics = get_statistics()
6669

@@ -88,8 +91,19 @@ def execute():
8891
except Exception as e:
8992
current_app.logger.error("Insert/Update failed on Last Execution stats")
9093
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
91104

92-
return jsonify(success=True)
105+
else:
106+
return jsonify({'outcome' : 'Unknown status: ' + str(job_outcome)}), 200
93107

94108

95109
def get_statistics():
@@ -157,6 +171,23 @@ def get_exec_status(job_id):
157171

158172
return exec_status
159173

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+
160191
def start_job():
161192
"""If no running jobs, create a job_id and execution status entry.
162193
This ensures only only one job runs at a time.

0 commit comments

Comments
 (0)