Exemple #1
0
def run_task(message):
    """
        Run the task from the given message
    """
    try:
        # create the task factory
        task_factory = TaskFactory()

        # check if we have a valid task
        task_factory.load_message(message)

        # get the task object
        task = task_factory.get_task()

        logger.info('Running task: {}'.format(task_factory.message))
        status = task.run()
        logger.info('Task status: {}'.format(status))

        # Send out the confirmation message
        logger.info('Confirming task execution for API: {}'.format(task.api_id))
        task.send_confirmation()

        return OS_SUCCESS
    except UnacceptableMessageException, e:
        logger.error('Could not create task factory for spawning tasks! Error: {}'.format(e))
        return OS_ERROR
Exemple #2
0
def run_task(message):
    """
        Run the task from the given message
    """
    try:
        # create the task factory
        task_factory = TaskFactory()

        # check if we have a valid task
        task_factory.load_message(message)

        # get the task object
        task = task_factory.get_task()

        logger.info('Running task: {}'.format(task_factory.message))
        status = task.run()
        logger.info('Task status: {}'.format(status))

        # Send out the confirmation message
        logger.info('Confirming task execution for API: {}'.format(
            task.api_id))
        task.send_confirmation()

        return OS_SUCCESS
    except UnacceptableMessageException, e:
        logger.error(
            'Could not create task factory for spawning tasks! Error: {}'.
            format(e))
        return OS_ERROR
Exemple #3
0
def test_constructor_with_valid_message():
    task_factory = TaskFactory()
    task_factory.load_message(json.dumps(deploy_message))
    assert task_factory.task_type() == DEPLOY_TASK

    task_factory.load_message(json.dumps(undeploy_message))
    assert task_factory.task_type() == UNDEPLOY_TASK

    task = task_factory.get_task()
    assert task.api_id == undeploy_message['api_id']
Exemple #4
0
def test_constructor_with_valid_message():
    task_factory = TaskFactory()
    task_factory.load_message(json.dumps(deploy_message))
    assert task_factory.task_type() == DEPLOY_TASK

    task_factory.load_message(json.dumps(undeploy_message))
    assert task_factory.task_type() == UNDEPLOY_TASK

    task = task_factory.get_task()
    assert task.api_id == undeploy_message['api_id']
Exemple #5
0
def test_constructor_with_missing_task_type():
    modified_message = {
        "api_id": "88sdhv98shdvlh123",
        "db_host": "db1.apitrary.net",
        "db_port": 8098,
        "genapi_version": 1,
        "log_level": "debug",
        "entities": ["user", "object", "contact"],
        "api_key": "iis9nd9vnsdvoijsdvoin9s8dv"
    }

    try:
        task_factory = TaskFactory()
        task_factory.load_message(modified_message)
    except UnacceptableMessageException:
        return True
    except Exception:
        return False
Exemple #6
0
def test_constructor_with_missing_task_type():
    modified_message = {
        "api_id": "88sdhv98shdvlh123",
        "db_host": "db1.apitrary.net",
        "db_port": 8098,
        "genapi_version": 1,
        "log_level": "debug",
        "entities": ["user", "object", "contact"],
        "api_key": "iis9nd9vnsdvoijsdvoin9s8dv"
    }

    try:
        task_factory = TaskFactory()
        task_factory.load_message(modified_message)
    except UnacceptableMessageException:
        return True
    except Exception:
        return False