skorper commented on code in PR #249: URL: https://github.com/apache/incubator-sdap-nexus/pull/249#discussion_r1279859712
########## analysis/webservice/algorithms/doms/ResultsStorage.py: ########## @@ -106,24 +106,39 @@ class ResultsStorage(AbstractResultsContainer): def __init__(self, config=None): AbstractResultsContainer.__init__(self, config) - def insertResults(self, results, params, stats, startTime, completeTime, userEmail, execution_id=None): - self._log.info('Beginning results write') + def insertInitialExecution(self, params, startTime, status, userEmail='', execution_id=None): + """ + Initial insert into database for CDMS matchup request. This + populates the execution and params table. + """ if isinstance(execution_id, str): execution_id = uuid.UUID(execution_id) - execution_id = self.insertExecution(execution_id, startTime, completeTime, userEmail) + execution_id = self.__insertExecution(execution_id, startTime, None, userEmail, status) self.__insertParams(execution_id, params) - self.__insertStats(execution_id, stats) - self.__insertResults(execution_id, results) - self._log.info('Results write finished') return execution_id - def insertExecution(self, execution_id, startTime, completeTime, userEmail): + def updateExecution(self, execution_id, completeTime, status, message, stats, results): + if stats: + self.__insertStats(execution_id, stats) + if results: + self.__insertResults(execution_id, results) + self.__updateExecution(execution_id, completeTime, status, message) + + def __insertExecution(self, execution_id, startTime, completeTime, userEmail, status): + """ + Insert new entry into execution table + """ if execution_id is None: execution_id = uuid.uuid4() - cql = "INSERT INTO doms_executions (id, time_started, time_completed, user_email) VALUES (%s, %s, %s, %s)" - self._session.execute(cql, (execution_id, startTime, completeTime, userEmail)) + cql = "INSERT INTO doms_executions (id, time_started, time_completed, user_email, status) VALUES (%s, %s, %s, %s, %s)" + self._session.execute(cql, (execution_id, startTime, completeTime, userEmail, status)) + return execution_id Review Comment: Done ########## analysis/webservice/webmodel/NexusExecutionResults.py: ########## @@ -0,0 +1,149 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +from enum import Enum + + +ISO_8601 = '%Y-%m-%dT%H:%M:%S%z' + + +class ExecutionStatus(Enum): + RUNNING = 'running' + SUCCESS = 'success' + FAILED = 'failed' + CANCELLED = 'cancelled' + + +def construct_job_status(job_state, created, updated, execution_id, params, host, message=''): + return { + 'status': job_state.value, + 'message': message, + 'createdAt': created, + 'updatedAt': updated, + 'links': [{ + 'href': f'{host}/job?id={execution_id}', + 'title': 'The current page', + 'type': 'application/json', + 'rel': 'self' + }], + 'params': params, + 'jobID': execution_id + } + + +def construct_done(status, created, completed, execution_id, params, host): + job_body = construct_job_status( + status, + created, + completed, + execution_id, + params, + host + ) + + # Construct urls + formats = [ + 'CSV', + 'JSON', + 'NETCDF' + ] + data_links = [{ + 'href': f'{host}/cdmsresults?id={execution_id}&output={output_format}', + 'title': 'Download results', + 'rel': 'data' + } for output_format in formats] Review Comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@sdap.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org