generate acquisiton (unique) number and provide it via rest-api to clients

This commit is contained in:
Dmitry Ozerov
2021-08-13 10:47:51 +02:00
committed by Data Backend account
parent 42a357ba68
commit 407bc0efd2
2 changed files with 40 additions and 0 deletions
+35
View File
@@ -64,6 +64,41 @@ class BrokerManager(object):
def __init__(self, broker_client):
self.broker_client = broker_client
def get_next_acquistion_number(self, request=None, remote_ip=None):
if not request:
return {"status" : "failed", "message" : "request parameters are empty"}
if not remote_ip:
return {"status" : "failed", "message" : "can not identify from which machine request were made"}
beamline = ip_to_console(remote_ip)
if not beamline:
return {"status" : "failed", "message" : "can not determine from which console request came, rejected"}
if "pgroup" not in request:
return {"status" : "failed", "message" : "no pgroup in request parameters"}
pgroup = request["pgroup"]
path_to_pgroup = f'/sf/{beamline}/data/{pgroup}/raw/'
if not os.path.exists(path_to_pgroup):
return {"status" : "failed", "message" : f'pgroup directory {path_to_pgroup} not reachable'}
daq_directory = f'{path_to_pgroup}{DIR_NAME_RUN_INFO}'
if not os.path.exists(daq_directory):
try:
os.mkdir(daq_directory)
except:
return {"status" : "failed", "message" : "no permission or possibility to make run_info directory in pgroup space"}
if os.path.exists(f'{daq_directory}/CLOSED'):
return {"status" : "failed", "message" : f'{path_to_pgroup} is closed for writing'}
next_run = get_current_run_number(daq_directory, file_run="LAST_ARUN")
return {"status" : "ok", "message" : str(next_run) }
def power_on_detector(self, request=None, remote_ip=None):
if not request:
+5
View File
@@ -30,6 +30,11 @@ def register_rest_interface(app, manager):
def power_on_detector():
return manager.power_on_detector(request=bottle.request.json, remote_ip=bottle.request.remote_addr)
@app.get("/get_next_acquistion_number")
def get_next_acquistion_number():
return manager.get_next_acquistion_number(request=bottle.request.json, remote_ip=bottle.request.remote_addr)
@app.error(500)
def error_handler_500(error):
bottle.response.content_type = 'application/json'