How to use the oasislmf.utils.status.STATUS_FAILURE function in oasislmf

To help you get started, we’ve selected a few oasislmf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OasisLMF / OasisPlatform / tests / test_analysis.py View on Github external
def test_celery_task_is_failure___result_is_failure(self):
        response = self.app.get('/analysis_status/{}'.format('location'))

        self.assertEqual(json.loads(response.data.decode('utf-8')), {
            'id': -1,
            'status': status.STATUS_FAILURE,
            'message': "'message'",
            'outputs_location': None,
        })
github OasisLMF / OasisPlatform / tests / test_analysis.py View on Github external
    @patch('src.server.app.CELERY.AsyncResult', Mock(return_value=fake_result('message', status.STATUS_FAILURE)))
    def test_celery_task_is_failure___result_is_failure(self):
        response = self.app.get('/analysis_status/{}'.format('location'))

        self.assertEqual(json.loads(response.data.decode('utf-8')), {
            'id': -1,
            'status': status.STATUS_FAILURE,
            'message': "'message'",
            'outputs_location': None,
        })
github OasisLMF / OasisPlatform / src / server.bak / app.py View on Github external
def _get_analysis_status(location):
    """
    Get the status of an analysis
    """
    result = CELERY.AsyncResult(location)
    logging.debug("celery result:{}".format(result.result))

    if result.state == status.STATUS_SUCCESS:
        analysis_status = data.AnalysisStatus(
            id=-1,
            status=status.STATUS_SUCCESS,
            message="",
            outputs_location=result.result)
    elif result.state == status.STATUS_FAILURE:
        analysis_status = data.AnalysisStatus(
            id=-1,
            status=status.STATUS_FAILURE,
            message=repr(result.result),
            outputs_location=None)
    else:
        analysis_status = data.AnalysisStatus(
            id=-1,
            status=result.state,
            message="",
            outputs_location=None)
    return analysis_status
github OasisLMF / OasisPlatform / src / server.bak / app.py View on Github external
description: The location of the outputs resource to download.
        required: true
        type: string
    """
    analysis_status = _get_analysis_status(location)

    # If there is no location for a successful analysis, retry once
    # and then fail the analysis as something has gone wrong
    if (analysis_status.status == status.STATUS_SUCCESS and analysis_status.outputs_location is None):
        logging.info("Successful analysis has no location - retrying")
        time.sleep(5)

        analysis_status = _get_analysis_status(location)
        if (analysis_status.status == status.STATUS_SUCCESS and analysis_status.outputs_location is None):
            logging.info("Successful analysis still has no location - fail")
            analysis_status.status = status.STATUS_FAILURE

    response = jsonify(analysis_status)
    logging.debug("Response: {}".format(response.data))

    return response