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 for Orquesta workflows #4400

Merged
merged 7 commits into from
Oct 19, 2018
Merged

Conversation

m4dcoder
Copy link
Contributor

Add support of with items and concurrency in the task spec of Orquesta workflows. This PR is dependent on changes in the Orquesta engine at StackStorm/orquesta#94. Unit and integration tests are written to cover single and multiple items list, with or without concurrency, and additional operations such as pause, resume, and cancel of workflow while the task is being executed. The following examples are different variations of how workflow authors can define with items for a task.

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) %>

Refactor workflow engine and service to add support of with items for orquesta workflows. The orquesta conductor adds more data when retrieving the next set of tasks for execution. The extra data includes one or more rendered action specs. Previously, there is only one action spec and it is rendered directly into the task spec. The workflow service is refactored to request the number of action executions as specified in the set of tasks returned from the conductor. Additional field is added into the DB model for task execution to indicate if it is with items. The action execution result for each item is stored differently in the task execution.
…items

For a task with items schedules multiple action executions concurrently, there is a conflict in updating the DB record for the task execution. Add the retry decorator for requesting action executions to retry on conflict. Refactor with items tests to allow more granular control of concurrency.
Refactor the workflow inspection unit tests to accomodate change in the workflow schema.
@m4dcoder m4dcoder requested a review from bigmstone October 18, 2018 23:05
…h items

Add integration tests to cover cancellation, pause, and resume of orquesta workflows that have tasks with items.
@m4dcoder m4dcoder force-pushed the orquesta-with-items branch from e723a25 to bfe3ff5 Compare October 19, 2018 00:30
@nzlosh
Copy link
Contributor

nzlosh commented Oct 19, 2018

Would it be possible to support an option asynchronous for with-items?

When a parent workflow uses with-items to loop over a large list and calls a sub-workflow the current (mistral) synchronous behaviour produces a batching effect where concurrent: X determines the number of sub-workflows are run to completion before executing the next X items.

I have a workflow where the sub-workflow upgrades machine packages, reboots the machine and checks the monitoring staus is OK. If in a single with-items iteration 9/10 complete in under 5 minutes but 1 takes 13 minutes, no subworkflows are executed until 13 minutes later. This is not ideal from a efficiency point of view.

If we had support for asynchronous with-items the behaviour would be to constrain the number of concurrent sub-workflows, but once a sub-workflow completes, then next sub-workflow is triggered immediately.

@m4dcoder
Copy link
Contributor Author

m4dcoder commented Oct 19, 2018

@nzlosh This implementation is already operating as you described. The Orquesta conductor will schedule the next item(s) as soon as there are free slots as defined by concurrency. Also, you may want to recheck Mistral, I don't recall it working batch like.

@nzlosh
Copy link
Contributor

nzlosh commented Oct 19, 2018

❤️ great news! Silly question, is there an option for synchronous with-items? :)

@m4dcoder
Copy link
Contributor Author

@nzlosh yep, concurrency=None 😜

@nzlosh
Copy link
Contributor

nzlosh commented Oct 19, 2018

Nice job, that's awesome!! 🥇 Thanks for the great work!

@m4dcoder m4dcoder force-pushed the orquesta-with-items branch from bfe3ff5 to de58582 Compare October 19, 2018 18:04
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.

Approved, just an obligatory reminder to clean up orquestra branch path.

Update the commit hash for orquesta in requirements to reference the required changes for with items task.
@m4dcoder m4dcoder force-pushed the orquesta-with-items branch from de58582 to e062c29 Compare October 19, 2018 22:03
@m4dcoder
Copy link
Contributor Author

@bigmstone Thanks. I just updated requirements.

@m4dcoder m4dcoder merged commit 9d90c65 into master Oct 19, 2018
@bigmstone bigmstone deleted the orquesta-with-items branch October 20, 2018 00:15
@Kami Kami added this to the 3.0.0 milestone Dec 4, 2018
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.

4 participants