diff --git a/webservice/webservice.py b/webservice/webservice.py index 5d51c4b1f4de81c1e59e510cde886c9f461cdd3b..0652255f006d1e2d5c91f6eeb525d07f428e5be9 100644 --- a/webservice/webservice.py +++ b/webservice/webservice.py @@ -1270,70 +1270,79 @@ class ActionsServer: async def _continue(): """Runs in the background after we reply to the 'dark_request' request""" await update_mdc_status(self.mdc, 'dark_request', rid, queued_msg) - transfer_complete = await wait_transfers( - self.mdc, runs, proposal, cycle, instrument - ) - if not transfer_complete: - # Timed out - await update_mdc_status( - self.mdc, 'dark_request', rid, MDC.MIGRATION_TIMEOUT + try: + transfer_complete = await wait_transfers( + self.mdc, runs, proposal, cycle, instrument + ) + if not transfer_complete: + # Timed out + await update_mdc_status( + self.mdc, 'dark_request', rid, MDC.MIGRATION_TIMEOUT + ) + return + + # Notebooks require one or three runs, depending on the + # detector type and operation mode. + triple = any( + det in karabo_id for det in + [ + "LPD", + "AGIPD", + "JUNGFRAU", + "JF", + "JNGFR", + "JUNGF", + "GH2", + "G2", + ]) + + # This fails silently if the hardcoded strings above are + # ever changed (triple = False) but the underlying notebook + # still expects run-high/run-med/run-low. + if triple and len(runs) == 1: + runs_dict = {'run-high': runs[0], + 'run-med': '0', + 'run-low': '0'} + elif triple and len(runs) == 3: + runs_dict = {'run-high': runs[0], + 'run-med': runs[1], + 'run-low': runs[2]} + else: # single + runs_dict = {'run': runs[0]} + + # We assume that MyMDC does not allow dark request if the data + # is not migrated, thus skipping some validation here. + thisconf = copy.copy(data_conf[karabo_id]) + + # Pop internal key to avoid propagation to xfel-calibrate. + thisconf.pop('disable-correct', None) + + if (karabo_id in pconf + and isinstance(pconf[karabo_id], dict)): + thisconf.update(copy.copy(pconf[karabo_id])) + + thisconf['in-folder'] = in_folder + thisconf['out-folder'] = out_folder + thisconf['karabo-id'] = karabo_id + thisconf['karabo-da'] = karabo_das + thisconf['operation-mode'] = operation_mode + + thisconf.update(runs_dict) + + detectors = {karabo_id: thisconf} + + ret, report_path = await self.launch_jobs( + runs, req_id, detectors, 'dark', instrument, cycle, proposal, + request_time + ) + except Exception as e: + msg = Errors.JOB_LAUNCH_FAILED.format('dark', e) + logging.error(msg, exc_info=e) + asyncio.ensure_future( + update_mdc_status(self.mdc, 'dark_request', rid, msg) ) return - # Notebooks require one or three runs, depending on the - # detector type and operation mode. - triple = any( - det in karabo_id for det in - [ - "LPD", - "AGIPD", - "JUNGFRAU", - "JF", - "JNGFR", - "JUNGF", - "GH2", - "G2", - ]) - - # This fails silently if the hardcoded strings above are - # ever changed (triple = False) but the underlying notebook - # still expects run-high/run-med/run-low. - if triple and len(runs) == 1: - runs_dict = {'run-high': runs[0], - 'run-med': '0', - 'run-low': '0'} - elif triple and len(runs) == 3: - runs_dict = {'run-high': runs[0], - 'run-med': runs[1], - 'run-low': runs[2]} - else: # single - runs_dict = {'run': runs[0]} - - # We assume that MyMDC does not allow dark request if the data - # is not migrated, thus skipping some validation here. - thisconf = copy.copy(data_conf[karabo_id]) - - # Pop internal key to avoid propagation to xfel-calibrate. - thisconf.pop('disable-correct', None) - - if (karabo_id in pconf - and isinstance(pconf[karabo_id], dict)): - thisconf.update(copy.copy(pconf[karabo_id])) - - thisconf['in-folder'] = in_folder - thisconf['out-folder'] = out_folder - thisconf['karabo-id'] = karabo_id - thisconf['karabo-da'] = karabo_das - thisconf['operation-mode'] = operation_mode - - thisconf.update(runs_dict) - - detectors = {karabo_id: thisconf} - - ret, report_path = await self.launch_jobs( - runs, req_id, detectors, 'dark', instrument, cycle, proposal, - request_time - ) await update_mdc_status(self.mdc, 'dark_request', rid, ret) if len(report_path) == 0: logging.warning("Failed to identify report path for dark_request")