-
Notifications
You must be signed in to change notification settings - Fork 64
Add version property to DurableOrchestrationContext class #557
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
86326ea
Add version property to DurableOrchestrationContext class
AnatoliB abef2bc
Fix test app output
AnatoliB d1178c3
Update azure/durable_functions/models/DurableOrchestrationContext.py
AnatoliB 043ce0c
Update azure/durable_functions/models/DurableOrchestrationContext.py
AnatoliB 5144d59
Fix tests
AnatoliB e592351
Fix comments
AnatoliB f71b40e
Update sample code and instructions
AnatoliB cd55f8e
Merge branch 'dev' into anatolib/context-version
AnatoliB f147cec
Minor fixes in README.md
AnatoliB 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
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,5 @@ | ||
.git* | ||
.vscode | ||
local.settings.json | ||
test | ||
.venv |
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,130 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don’t work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# Azure Functions artifacts | ||
bin | ||
obj | ||
appsettings.json | ||
local.settings.json | ||
.python_packages |
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,3 @@ | ||
# Versioning | ||
|
||
This directory contains a Function app that demonstrates how to make changes to an orchestrator function without breaking existing orchestration instances. | ||
AnatoliB marked this conversation as resolved.
Show resolved
Hide resolved
|
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,48 @@ | ||
import logging | ||
import azure.functions as func | ||
import azure.durable_functions as df | ||
|
||
myApp = df.DFApp(http_auth_level=func.AuthLevel.ANONYMOUS) | ||
|
||
@myApp.route(route="orchestrators/{functionName}") | ||
@myApp.durable_client_input(client_name="client") | ||
async def http_start(req: func.HttpRequest, client): | ||
function_name = req.route_params.get('functionName') | ||
instance_id = await client.start_new(function_name) | ||
|
||
logging.info(f"Started orchestration with ID = '{instance_id}'.") | ||
return client.create_check_status_response(req, instance_id) | ||
|
||
@myApp.orchestration_trigger(context_name="context") | ||
def my_orchestrator(context: df.DurableOrchestrationContext): | ||
if (context.version == "1.0"): | ||
# Legacy code path | ||
activity_result = yield context.call_activity('say_hello', "v1.0") | ||
else: | ||
# New code path | ||
activity_result = yield context.call_activity('say_hello', "v2.0") | ||
|
||
""" | ||
While the orchestration is waiting for the external event, | ||
stop the app, update the defaultVersion in host.json to "2.0", | ||
then restart the app and send a "Continue" event. | ||
This orchestration instance should continue with the old version. | ||
""" | ||
AnatoliB marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
context.set_custom_status("Waiting for Continue event...") | ||
yield context.wait_for_external_event("Continue") | ||
context.set_custom_status("Continue event received") | ||
|
||
""" | ||
New orchestration instances (including sub-orchestrations) | ||
will use the current defaultVersion specified in host.json. | ||
""" | ||
sub_result = yield context.call_sub_orchestrator('my_sub_orchestrator') | ||
return [f'Orchestration version: {context.version}', f'Suborchestration version: {sub_result}', activity_result] | ||
|
||
@myApp.orchestration_trigger(context_name="context") | ||
def my_sub_orchestrator(context: df.DurableOrchestrationContext): | ||
return context.version | ||
|
||
@myApp.activity_trigger(input_name="city") | ||
def say_hello(city: str) -> str: | ||
return f"Hello {city}!" |
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,16 @@ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"applicationInsights": { | ||
"samplingSettings": { | ||
"isEnabled": true, | ||
"excludedTypes": "Request" | ||
} | ||
} | ||
}, | ||
"extensions": { | ||
"durableTask": { | ||
"defaultVersion": "1.0" | ||
AnatoliB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
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,7 @@ | ||
# DO NOT include azure-functions-worker in this file | ||
# The Python Worker is managed by Azure Functions platform | ||
# Manually managing azure-functions-worker may cause unexpected issues | ||
|
||
azure-functions | ||
azure-functions-durable | ||
pytest |
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
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.
Uh oh!
There was an error while loading. Please reload this page.