Exportable & importable workflow state + execution #3317
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for the workflows runtime to export a given workflow's state so that it can be executed "in-process".
This enables scenarios where a workflow needs access to the HTTP context. Depending on the runtime, this may or may not be accessible.
For example, the Proto Actor workflow runtime implementation executes workflows in virtual actors (grains) which you can think of as being background processes which do not have access to HTTP response contexts when e.g. the workflow is triggered from an HTTP request.
The solution chosen here is to let the workflow execute in the grain until the WriteHttpResponse activity is encountered, which internally checks to see if it is executing within an HTTP context (which is not the case for grains). If this is not the case, the activity creates a resumable bookmark.
It is then up to the workflow invoker to identify these bookmarks and resume the workflow "externally" by exporting the workflow state from the runtime, resuming the workflow using the bookmarks, and then importing the state again.
One final improvement to be considered is to implement a locking mechanism to avoid workflow state concurrency issues. For example, it is possible that a workflow has a Delay activity that triggers at the time where the workflow state was exported and is executed outside of the grain. If the exported state is then imported, that state will be "stale" since the grain's internal workflow state will have been updated since the export.
Instead of locking, we could also consider merging states.