Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement with items in task of native spec #94

Merged
merged 24 commits into from
Oct 19, 2018
Merged

Implement with items in task of native spec #94

merged 24 commits into from
Oct 19, 2018

Conversation

m4dcoder
Copy link
Collaborator

@m4dcoder m4dcoder commented Oct 12, 2018

Implement the following variations for with items in task of native spec. Add support in the conductor to handle various use cases for concurrency and other state changes such as pause, pending, resume, and cancel. If no concurrency is defined, than action executions for each items will be launched immediately. Otherwise, if concurrency is defined, the conductor will direct the execution as items are completed. Also, if not concurrency is required, workflow author can use short hand shown in examples below.

task1:
  with: <% ctx(x) %>
  action: core.echo message=<% item() %>
task1:
  with:
    items: <% ctx(x) %>
    concurrency: 2
  action: core.echo message=<% item() %>
task1:
  with: i in <% ctx(x) %>
  action: core.echo message=<% item(i) %>
task1:
  with:
    items: i in <% ctx(x) %>
    concurrency: 2
  action: core.echo message=<% item(i) %>
task1:
  with: i, j in <% zip(ctx(x), ctx(y)) %>
  action: mock.foobar a=<% item(i) %> b=<% item(j) %>
task1:
  with:
    items: i, j in <% zip(ctx(x), ctx(y)) %>
    concurrency: 2
  action: mock.foobar a=<% item(i) %> b=<% item(j) %>

Add zip function for use in expressions. The zip function is similar to python zip functions which takes x number of list and return a list of tuples where each tuple contains elements from each lists.
Add a function in utility to unescape escaped characters in string.
Add a property named `with` to the native task spec in support of with items. The `with` property in the json schema is type of string with a regular expression to match the patterns "x in <expression>" or "x, y, ... in <expression>". Add unit tests to cover validation of various patterns.
Add support for fully modeled with items with additional attributes such as concurrency in task spec. Continue to support the shorthand inline version of with items.
Add an item function for expressions to retrieve current item from the context.
Add support of with items in the conducting when the task spec is evaluated and being rendered.
Make sure that once a task has already progressed, repeated calls to get next tasks, specifically by task name, will not return duplicates.
Add context to the ExecutionEvent class. Information related to the task item that is associated with the action execution will be passed into the context for processing.
The method get_next_tasks in the conductor already serves similar role as get_start_tasks. Remove get_start_tasks to minimize confusion on use and duplication of code.
Add concurrency to the task spec, ensure conductor returns appropriate number of items in get_next_tasks, and that action execution event related to an item is processed correctly with appropriate task state change.
Add examples for single and multiple items list with and without concurrency.
…rocessed

Move the execution of the engine commands until the current task is processed. Currently the engine commands identified in the task transition will be immediately executed and this may causes problems where the current task needs to be completed processing.
Add more comments, shuffle, and remove duplicate codes for getting task result, removing staged task, and evaluating task transitions.
Move the rendering logic to the task spec so it's more specific to the specific workflow definition language.
Ensure that pausing and pending an action executions of task with items are handled properly.
Ensure that canceling an action executions of task with items are handled properly.
Ensure the task with items is in running state if any related action executions is still active. This ensures that action executions related to the task in a previous cycle is not going to overwrite the item state and result for the latest cycle.
…ancel

On various use cases for task with items that is active or dormant and with or without concurrency, ensure that the task state is handled properly on request to change workflow state to pause, resume, or cancel.
@m4dcoder m4dcoder requested a review from bigmstone October 12, 2018 22:38
@codecov-io
Copy link

codecov-io commented Oct 12, 2018

Codecov Report

Merging #94 into master will decrease coverage by 0.13%.
The diff coverage is 93.1%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #94      +/-   ##
==========================================
- Coverage   94.24%   94.11%   -0.14%     
==========================================
  Files          37       38       +1     
  Lines        2102     2309     +207     
  Branches      400      453      +53     
==========================================
+ Hits         1981     2173     +192     
- Misses         72       79       +7     
- Partials       49       57       +8
Impacted Files Coverage Δ
orquesta/expressions/jinja.py 92.18% <100%> (+0.06%) ⬆️
orquesta/expressions/yql.py 89.24% <100%> (+0.11%) ⬆️
orquesta/specs/native/v1/models.py 97.68% <100%> (+0.33%) ⬆️
orquesta/expressions/functions/workflow.py 100% <100%> (ø) ⬆️
orquesta/events.py 100% <100%> (ø) ⬆️
orquesta/expressions/functions/common.py 100% <100%> (ø) ⬆️
orquesta/utils/strings.py 100% <100%> (ø)
orquesta/utils/context.py 90.47% <66.66%> (-9.53%) ⬇️
orquesta/states/machines.py 88% <84.33%> (-1.82%) ⬇️
orquesta/specs/mistral/v2/tasks.py 95.16% <90%> (-0.46%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 851b145...85e86c4. Read the comment docs.

Add a unit test to cover basic performance on the conductor runtime as a function of the number of items in a task with items.
@@ -333,19 +333,20 @@ def _render_task_spec(self, task_name, ctx_value):
else items_spec.items[:items_spec.items.index('in')].replace(' ', '').split(',')
)

for item in items:
current_item = item
for i in range(0, len(items)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could swap for enumerate

Copy link
Contributor

@bigmstone bigmstone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

else items_spec.items[:items_spec.items.index('in')].replace(' ', '').split(',')
)

for i in range(0, len(items)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could simplify to enumerate. Not a blocker.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I will refactor.

If the with items concurrency is an expression, the expression is not evaluated. Fix the issue and add unit tests coverage.
The conductor currently handles pausing and canceling states but not paused and canceled states on request workflow state. This patch adds the appropriate list of events and mappings to the task state machine.
@m4dcoder m4dcoder merged commit 142a19d into master Oct 19, 2018
@m4dcoder m4dcoder deleted the with-items branch October 19, 2018 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants