From cba6b493f236a568943e7b662494bc9940d4142d Mon Sep 17 00:00:00 2001 From: Renat Akhmerov Date: Wed, 19 Apr 2017 17:17:09 +0700 Subject: [PATCH] Add 'runtime_context' to task execution REST resource Partially implements: blueprint mistral-previous-tasks Change-Id: I8aacadd69b6991bbd09aab0226d2c001bbe43085 --- mistral/api/controllers/v2/resources.py | 10 ++++++++++ mistral/tests/unit/api/v2/test_tasks.py | 13 +++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/mistral/api/controllers/v2/resources.py b/mistral/api/controllers/v2/resources.py index 0069b532a..ad24c4c12 100644 --- a/mistral/api/controllers/v2/resources.py +++ b/mistral/api/controllers/v2/resources.py @@ -289,6 +289,8 @@ class Task(resource.Resource): state_info = wtypes.text "an optional state information string" + runtime_context = types.jsontype + result = wtypes.text published = types.jsontype processed = bool @@ -310,6 +312,14 @@ class Task(resource.Resource): workflow_execution_id='123e4567-e89b-12d3-a456-426655440000', name='task', state=states.SUCCESS, + runtime_context={ + 'triggered_by': [ + { + 'task_id': '123-123-123', + 'event': 'on-success' + } + ] + }, result='task result', published={'key': 'value'}, processed=True, diff --git a/mistral/tests/unit/api/v2/test_tasks.py b/mistral/tests/unit/api/v2/test_tasks.py index 4213f60d9..4666e11ee 100644 --- a/mistral/tests/unit/api/v2/test_tasks.py +++ b/mistral/tests/unit/api/v2/test_tasks.py @@ -30,6 +30,14 @@ from mistral.workflow import states RESULT = {"some": "result"} PUBLISHED = {"var": "val"} +RUNTIME_CONTEXT = { + 'triggered_by': [ + { + 'task_id': '123-123-123', + 'event': 'on-success' + } + ] +} WF_EX = models.WorkflowExecution( id='abc', @@ -59,7 +67,7 @@ TASK_EX = models.TaskExecution( state=states.RUNNING, tags=['a', 'b'], in_context={}, - runtime_context={}, + runtime_context=RUNTIME_CONTEXT, workflow_execution_id=WF_EX.id, created_at=datetime.datetime(1970, 1, 1), updated_at=datetime.datetime(1970, 1, 1), @@ -82,7 +90,7 @@ WITH_ITEMS_TASK_EX = models.TaskExecution( state=states.RUNNING, tags=['a', 'b'], in_context={}, - runtime_context={}, + runtime_context=RUNTIME_CONTEXT, workflow_execution_id=WF_EX.id, created_at=datetime.datetime(1970, 1, 1), updated_at=datetime.datetime(1970, 1, 1), @@ -101,6 +109,7 @@ TASK = { 'updated_at': '1970-01-01 00:00:00', 'result': json.dumps(RESULT), 'published': json.dumps(PUBLISHED), + 'runtime_context': json.dumps(RUNTIME_CONTEXT), 'processed': True }