Skip to content

Commit

Permalink
Modify execution request handling
Browse files Browse the repository at this point in the history
  • Loading branch information
NaniteBased committed Dec 21, 2020
1 parent c7cb1cf commit 00624e8
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions Scheduler/dispatcher/routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import jsonify, request
from flask import jsonify, request, abort
from Status import ExecutionQueue
from Data import ExperimentDescriptor
from Scheduler.dispatcher import bp
Expand All @@ -7,27 +7,24 @@

@bp.route('/run', methods=['POST'])
def start():
data = request.json
Log.I("Received execution request")
Log.D(f"Payload: {data}")
descriptor = ExperimentDescriptor(data)
valid, reasons = descriptor.ValidityCheck
try:
data = request.json
Log.I("Received execution request")
Log.D(f"Payload: {data}")

if not valid:
executionId = None
success = False
message = f'Invalid experiment description: {"; ".join(reasons)}'
else:
params = {'Descriptor': descriptor}
executionId = ExecutionQueue.Create(params).Id
success = True
message = f'Created execution {executionId}'
if data is None:
raise RuntimeError("Received empty payload")

descriptor = ExperimentDescriptor(data)
valid, reasons = descriptor.ValidityCheck

response = {
'ExecutionId': executionId,
'Success': success,
'Message': message
}
if not valid:
raise RuntimeError(f'Invalid experiment description: {"; ".join(reasons)}')

Log.D(f"Response: {response}")
return jsonify(response)
params = {'Descriptor': descriptor}
executionId = ExecutionQueue.Create(params).Id
return jsonify({'ExecutionId': executionId})
except Exception as e:
message = f"Exception while processing execution request: {e}"
Log.W(message)
return abort(400, message)

0 comments on commit 00624e8

Please sign in to comment.