-
Notifications
You must be signed in to change notification settings - Fork 14
Cleanup readme #48
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
Open
greenie-msft
wants to merge
5
commits into
microsoft:main
Choose a base branch
from
greenie-msft:cleanup-readme
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Cleanup readme #48
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Contributing | ||
|
||
This project welcomes contributions and suggestions. Most contributions require you to agree to a | ||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us | ||
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. | ||
|
||
When you submit a pull request, a CLA bot will automatically determine whether you need to provide | ||
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions | ||
provided by the bot. You will only need to do this once across all repos using our CLA. | ||
|
||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). | ||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or | ||
contact [[email protected]](mailto:[email protected]) with any additional questions or comments. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,207 +4,20 @@ | |
[](https://github.com/microsoft/durabletask-python/actions/workflows/pr-validation.yml) | ||
[](https://badge.fury.io/py/durabletask) | ||
|
||
This repo contains a Python SDK for use with the [Azure Durable Task Scheduler](https://techcommunity.microsoft.com/blog/appsonazureblog/announcing-limited-early-access-of-the-durable-task-scheduler-for-azure-durable-/4286526) and the [Durable Task Framework for Go](https://github.com/microsoft/durabletask-go). With this SDK, you can define, schedule, and manage durable orchestrations using ordinary Python code. | ||
This repo contains a Python SDK for use with the [Azure Durable Task Scheduler](https://github.com/Azure/Durable-Task-Scheduler). With this SDK, you can define, schedule, and manage durable orchestrations using ordinary Python code. | ||
|
||
⚠️ **This SDK is currently under active development and is not yet ready for production use.** ⚠️ | ||
⚠️ This SDK is currently under active development and is evolving rapidly. While it's not yet ready for production use, we are excited about its potential and look forward to your feedback as we continue to improve it. ⚠️ | ||
|
||
> Note that this SDK is **not** currently compatible with [Azure Durable Functions](https://docs.microsoft.com/azure/azure-functions/durable/durable-functions-overview). If you are looking for a Python SDK for Azure Durable Functions, please see [this repo](https://github.com/Azure/azure-functions-durable-python). | ||
> Note that this SDK is **not** currently compatible with [Azure Durable Functions](https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-overview). If you are looking for a Python SDK for Azure Durable Functions, please see [this repo](https://github.com/Azure/azure-functions-durable-python). | ||
|
||
## Supported patterns | ||
|
||
The following orchestration patterns are currently supported. | ||
|
||
### Function chaining | ||
|
||
An orchestration can chain a sequence of function calls using the following syntax: | ||
|
||
```python | ||
# simple activity function that returns a greeting | ||
def hello(ctx: task.ActivityContext, name: str) -> str: | ||
return f'Hello {name}!' | ||
|
||
# orchestrator function that sequences the activity calls | ||
def sequence(ctx: task.OrchestrationContext, _): | ||
result1 = yield ctx.call_activity(hello, input='Tokyo') | ||
result2 = yield ctx.call_activity(hello, input='Seattle') | ||
result3 = yield ctx.call_activity(hello, input='London') | ||
|
||
return [result1, result2, result3] | ||
``` | ||
|
||
You can find the full sample [here](./examples/activity_sequence.py). | ||
|
||
### Fan-out/fan-in | ||
|
||
An orchestration can fan-out a dynamic number of function calls in parallel and then fan-in the results using the following syntax: | ||
|
||
```python | ||
# activity function for getting the list of work items | ||
def get_work_items(ctx: task.ActivityContext, _) -> List[str]: | ||
# ... | ||
|
||
# activity function for processing a single work item | ||
def process_work_item(ctx: task.ActivityContext, item: str) -> int: | ||
# ... | ||
|
||
# orchestrator function that fans-out the work items and then fans-in the results | ||
def orchestrator(ctx: task.OrchestrationContext, _): | ||
# the number of work-items is unknown in advance | ||
work_items = yield ctx.call_activity(get_work_items) | ||
|
||
# fan-out: schedule the work items in parallel and wait for all of them to complete | ||
tasks = [ctx.call_activity(process_work_item, input=item) for item in work_items] | ||
results = yield task.when_all(tasks) | ||
|
||
# fan-in: summarize and return the results | ||
return {'work_items': work_items, 'results': results, 'total': sum(results)} | ||
``` | ||
|
||
You can find the full sample [here](./examples/fanout_fanin.py). | ||
|
||
### Human interaction and durable timers | ||
|
||
An orchestration can wait for a user-defined event, such as a human approval event, before proceding to the next step. In addition, the orchestration can create a timer with an arbitrary duration that triggers some alternate action if the external event hasn't been received: | ||
|
||
```python | ||
def purchase_order_workflow(ctx: task.OrchestrationContext, order: Order): | ||
"""Orchestrator function that represents a purchase order workflow""" | ||
# Orders under $1000 are auto-approved | ||
if order.Cost < 1000: | ||
return "Auto-approved" | ||
|
||
# Orders of $1000 or more require manager approval | ||
yield ctx.call_activity(send_approval_request, input=order) | ||
|
||
# Approvals must be received within 24 hours or they will be canceled. | ||
approval_event = ctx.wait_for_external_event("approval_received") | ||
timeout_event = ctx.create_timer(timedelta(hours=24)) | ||
winner = yield task.when_any([approval_event, timeout_event]) | ||
if winner == timeout_event: | ||
return "Canceled" | ||
|
||
# The order was approved | ||
yield ctx.call_activity(place_order, input=order) | ||
approval_details = approval_event.get_result() | ||
return f"Approved by '{approval_details.approver}'" | ||
``` | ||
|
||
As an aside, you'll also notice that the example orchestration above works with custom business objects. Support for custom business objects includes support for custom classes, custom data classes, and named tuples. Serialization and deserialization of these objects is handled automatically by the SDK. | ||
|
||
You can find the full sample [here](./examples/human_interaction.py). | ||
|
||
## Feature overview | ||
|
||
The following features are currently supported: | ||
|
||
### Orchestrations | ||
|
||
Orchestrations are implemented using ordinary Python functions that take an `OrchestrationContext` as their first parameter. The `OrchestrationContext` provides APIs for starting child orchestrations, scheduling activities, and waiting for external events, among other things. Orchestrations are fault-tolerant and durable, meaning that they can automatically recover from failures and rebuild their local execution state. Orchestrator functions must be deterministic, meaning that they must always produce the same output given the same input. | ||
|
||
### Activities | ||
|
||
Activities are implemented using ordinary Python functions that take an `ActivityContext` as their first parameter. Activity functions are scheduled by orchestrations and have at-least-once execution guarantees, meaning that they will be executed at least once but may be executed multiple times in the event of a transient failure. Activity functions are where the real "work" of any orchestration is done. | ||
|
||
### Durable timers | ||
|
||
Orchestrations can schedule durable timers using the `create_timer` API. These timers are durable, meaning that they will survive orchestrator restarts and will fire even if the orchestrator is not actively in memory. Durable timers can be of any duration, from milliseconds to months. | ||
|
||
### Sub-orchestrations | ||
|
||
Orchestrations can start child orchestrations using the `call_sub_orchestrator` API. Child orchestrations are useful for encapsulating complex logic and for breaking up large orchestrations into smaller, more manageable pieces. | ||
|
||
### External events | ||
|
||
Orchestrations can wait for external events using the `wait_for_external_event` API. External events are useful for implementing human interaction patterns, such as waiting for a user to approve an order before continuing. | ||
|
||
### Continue-as-new (TODO) | ||
|
||
Orchestrations can be continued as new using the `continue_as_new` API. This API allows an orchestration to restart itself from scratch, optionally with a new input. | ||
|
||
### Suspend, resume, and terminate | ||
|
||
Orchestrations can be suspended using the `suspend_orchestration` client API and will remain suspended until resumed using the `resume_orchestration` client API. A suspended orchestration will stop processing new events, but will continue to buffer any that happen to arrive until resumed, ensuring that no data is lost. An orchestration can also be terminated using the `terminate_orchestration` client API. Terminated orchestrations will stop processing new events and will discard any buffered events. | ||
|
||
### Retry policies (TODO) | ||
|
||
Orchestrations can specify retry policies for activities and sub-orchestrations. These policies control how many times and how frequently an activity or sub-orchestration will be retried in the event of a transient error. | ||
|
||
## Getting Started | ||
|
||
### Prerequisites | ||
|
||
- Python 3.9 | ||
- A Durable Task-compatible sidecar, like [Dapr Workflow](https://docs.dapr.io/developing-applications/building-blocks/workflow/workflow-overview/) | ||
|
||
### Installing the Durable Task Python client SDK | ||
|
||
Installation is currently only supported from source. Ensure pip, setuptools, and wheel are up-to-date. | ||
|
||
```sh | ||
python3 -m pip install --upgrade pip setuptools wheel | ||
``` | ||
|
||
To install this package from source, clone this repository and run the following command from the project root: | ||
|
||
```sh | ||
python3 -m pip install . | ||
``` | ||
|
||
### Run the samples | ||
|
||
See the [examples](./examples) directory for a list of sample orchestrations and instructions on how to run them. | ||
|
||
## Development | ||
|
||
The following is more information about how to develop this project. Note that development commands require that `make` is installed on your local machine. If you're using Windows, you can install `make` using [Chocolatey](https://chocolatey.org/) or use WSL. | ||
|
||
### Generating protobufs | ||
|
||
```sh | ||
pip3 install -r dev-requirements.txt | ||
make gen-proto | ||
``` | ||
|
||
This will download the `orchestrator_service.proto` from the `microsoft/durabletask-protobuf` repo and compile it using `grpcio-tools`. The version of the source proto file that was downloaded can be found in the file `durabletask/internal/PROTO_SOURCE_COMMIT_HASH`. | ||
|
||
### Running unit tests | ||
|
||
Unit tests can be run using the following command from the project root. Unit tests _don't_ require a sidecar process to be running. | ||
|
||
```sh | ||
make test-unit | ||
``` | ||
|
||
### Running E2E tests | ||
|
||
The E2E (end-to-end) tests require a sidecar process to be running. You can use the Dapr sidecar for this or run a Durable Task test sidecar using the following `docker` command: | ||
|
||
```sh | ||
docker run --name durabletask-sidecar -p 4001:4001 --env 'DURABLETASK_SIDECAR_LOGLEVEL=Debug' --rm cgillum/durabletask-sidecar:latest start --backend Emulator | ||
``` | ||
|
||
To run the E2E tests, run the following command from the project root: | ||
|
||
```sh | ||
make test-e2e | ||
``` | ||
|
||
## Contributing | ||
|
||
This project welcomes contributions and suggestions. Most contributions require you to agree to a | ||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us | ||
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. | ||
|
||
When you submit a pull request, a CLA bot will automatically determine whether you need to provide | ||
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions | ||
provided by the bot. You will only need to do this once across all repos using our CLA. | ||
|
||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). | ||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or | ||
contact [[email protected]](mailto:[email protected]) with any additional questions or comments. | ||
# References | ||
- [Supported Patterns](./docs/supported-patterns.md) | ||
- [Available Features](./docs/features.md) | ||
- [Getting Started](./docs/getting-started.md) | ||
- [Development Guide](./docs/development.md) | ||
- [Contributing Guide](./CONTRIBUTING.md) | ||
|
||
## Trademarks | ||
|
||
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft | ||
trademarks or logos is subject to and must follow | ||
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Development | ||
|
||
The following is more information about how to develop this project. Note that development commands require that `make` is installed on your local machine. If you're using Windows, you can install `make` using [Chocolatey](https://chocolatey.org/) or use WSL. | ||
|
||
### Generating protobufs | ||
|
||
```sh | ||
pip3 install -r dev-requirements.txt | ||
make gen-proto | ||
``` | ||
|
||
This will download the `orchestrator_service.proto` from the `microsoft/durabletask-protobuf` repo and compile it using `grpcio-tools`. The version of the source proto file that was downloaded can be found in the file `durabletask/internal/PROTO_SOURCE_COMMIT_HASH`. | ||
|
||
### Running unit tests | ||
|
||
Unit tests can be run using the following command from the project root. Unit tests _don't_ require a sidecar process to be running. | ||
|
||
```sh | ||
make test-unit | ||
``` | ||
|
||
### Running E2E tests | ||
|
||
The E2E (end-to-end) tests require a sidecar process to be running. You can use the Durable Task test sidecar using the following `docker` command: | ||
|
||
```sh | ||
docker run --name durabletask-sidecar -p 4001:4001 --env 'DURABLETASK_SIDECAR_LOGLEVEL=Debug' --rm cgillum/durabletask-sidecar:latest start --backend Emulator | ||
``` | ||
|
||
To run the E2E tests, run the following command from the project root: | ||
|
||
```sh | ||
make test-e2e | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Feature overview | ||
|
||
The following features are currently supported: | ||
|
||
### Orchestrations | ||
|
||
Orchestrations are implemented using ordinary Python functions that take an `OrchestrationContext` as their first parameter. The `OrchestrationContext` provides APIs for starting child orchestrations, scheduling activities, and waiting for external events, among other things. Orchestrations are fault-tolerant and durable, meaning that they can automatically recover from failures and rebuild their local execution state. Orchestrator functions must be deterministic, meaning that they must always produce the same output given the same input. | ||
|
||
### Activities | ||
|
||
Activities are implemented using ordinary Python functions that take an `ActivityContext` as their first parameter. Activity functions are scheduled by orchestrations and have at-least-once execution guarantees, meaning that they will be executed at least once but may be executed multiple times in the event of a transient failure. Activity functions are where the real "work" of any orchestration is done. | ||
|
||
### Durable timers | ||
|
||
Orchestrations can schedule durable timers using the `create_timer` API. These timers are durable, meaning that they will survive orchestrator restarts and will fire even if the orchestrator is not actively in memory. Durable timers can be of any duration, from milliseconds to months. | ||
|
||
### Sub-orchestrations | ||
|
||
Orchestrations can start child orchestrations using the `call_sub_orchestrator` API. Child orchestrations are useful for encapsulating complex logic and for breaking up large orchestrations into smaller, more manageable pieces. | ||
|
||
### External events | ||
|
||
Orchestrations can wait for external events using the `wait_for_external_event` API. External events are useful for implementing human interaction patterns, such as waiting for a user to approve an order before continuing. | ||
|
||
### Continue-as-new | ||
|
||
Orchestrations can be continued as new using the `continue_as_new` API. This API allows an orchestration to restart itself from scratch, optionally with a new input. | ||
|
||
### Suspend, resume, and terminate | ||
|
||
Orchestrations can be suspended using the `suspend_orchestration` client API and will remain suspended until resumed using the `resume_orchestration` client API. A suspended orchestration will stop processing new events, but will continue to buffer any that happen to arrive until resumed, ensuring that no data is lost. An orchestration can also be terminated using the `terminate_orchestration` client API. Terminated orchestrations will stop processing new events and will discard any buffered events. | ||
|
||
### Retry policies | ||
|
||
Orchestrations can specify retry policies for activities and sub-orchestrations. These policies control how many times and how frequently an activity or sub-orchestration will be retried in the event of a transient error. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Getting Started | ||
|
||
### Run the Order Processing Example | ||
- Check out the [Durable Task Scheduler example](../examples/dts/sub-orchestrations-with-fan-out-fan-in/README.md) | ||
for detailed instructions on running the order processing example. | ||
|
||
### Explore Other Samples | ||
- Visit the [examples](../examples/dts/) directory to find a variety of sample orchestrations and learn how to run them. | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I see you're removing whitespace between titles and content, but MS Learn markdown conventions require an extra newline between section titles and content. I suggest we do the same here.
Suggested VS Code extension: https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint