-
Notifications
You must be signed in to change notification settings - Fork 19
Creation of DTS example and passing of completionToken #40
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
RyanLettieri
merged 32 commits into
microsoft:main
from
RyanLettieri:durabletask-scheduler
Feb 18, 2025
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
026c572
Creation of DTS example and passing of completionToken
RyanLettieri 136a3d0
Adressing review feedback
RyanLettieri 6df1064
Reverting dapr readme
RyanLettieri f731c0d
Adding accessTokenManager class for refreshing credential token
RyanLettieri eb98416
Adding comments to the example
RyanLettieri 0de338d
Adding in requirement for azure-identity
RyanLettieri 6050771
Moving dts logic into its own module
RyanLettieri f4f98ee
Fixing whitesapce
RyanLettieri ea837d0
Updating dts client to refresh token
RyanLettieri f8d79d3
Cleaning up construction of dts objects and improving examples
RyanLettieri 1e67651
Migrating shared access token logic to new grpc class
RyanLettieri 6b1bfd2
Adding log statements to access_token_manager
RyanLettieri bd56a35
breaking for loop when setting interceptors
RyanLettieri efc0146
Removing changes to client.py and adding additional steps to readme.md
RyanLettieri 3fd0b08
Refactoring client and worker to pass around interceptors
RyanLettieri 4260d02
Fixing import for DefaultClientInterceptorImpl
RyanLettieri ec4617c
Adressing round 1 of feedback
RyanLettieri ed733ea
Fixing interceptor issue
RyanLettieri 99f62d7
Moving some files around to remove dependencies
RyanLettieri f9d55ab
Adressing more feedback
RyanLettieri ba1ac4f
More review feedback
RyanLettieri 2c251ea
Passing token credential as an argument rather than 2 strings
RyanLettieri 9c65176
More review feedback for token passing
RyanLettieri 877dabb
Addressing None comment and using correct metadata
RyanLettieri b39ffad
Updating unit tests
RyanLettieri 33c8b11
Fixing the type for the unit test
RyanLettieri 1da819e
Fixing grpc calls
RyanLettieri f690264
Merge branch 'main' into durabletask-scheduler
RyanLettieri 6142220
Fix linter errors and update documentation
cgillum 58f4f93
Specifying version reqiuirement for pyproject.toml
RyanLettieri d82c1b7
Updating README
RyanLettieri b3a099e
Adding comment for credential type
RyanLettieri 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
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,73 @@ | ||
| import os | ||
| from azure.identity import DefaultAzureCredential | ||
|
|
||
| """End-to-end sample that demonstrates how to configure an orchestrator | ||
| that calls an activity function in a sequence and prints the outputs.""" | ||
| from durabletask import client, task, worker | ||
|
|
||
|
|
||
| def hello(ctx: task.ActivityContext, name: str) -> str: | ||
| """Activity function that returns a greeting""" | ||
| return f'Hello {name}!' | ||
|
|
||
|
|
||
| def sequence(ctx: task.OrchestrationContext, _): | ||
| """Orchestrator function that calls the 'hello' activity function in a sequence""" | ||
| # call "hello" activity function in a sequence | ||
| 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 an array of results | ||
| return [result1, result2, result3] | ||
|
|
||
|
|
||
| # Read the environment variable | ||
| taskhub_name = os.getenv("TASKHUB") | ||
|
|
||
| # Check if the variable exists | ||
| if taskhub_name: | ||
| print(f"The value of TASKHUB is: {taskhub_name}") | ||
| else: | ||
| print("TASKHUB is not set. Please set the TASKHUB environment variable to the name of the taskhub you wish to use") | ||
| print("If you are using windows powershell, run the following: $env:TASKHUB=\"<taskhubname>\"") | ||
| print("If you are using bash, run the following: export TASKHUB=\"<taskhubname>\"") | ||
| exit() | ||
|
|
||
| # Read the environment variable | ||
| endpoint = os.getenv("ENDPOINT") | ||
|
|
||
| # Check if the variable exists | ||
| if endpoint: | ||
| print(f"The value of ENDPOINT is: {endpoint}") | ||
| else: | ||
| print("ENDPOINT is not set. Please set the ENDPOINT environment variable to the endpoint of the taskhub") | ||
| print("If you are using windows powershell, run the following: $env:ENDPOINT=\"<taskhubEndpoint>\"") | ||
RyanLettieri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| print("If you are using bash, run the following: export ENDPOINT=\"<taskhubEndpoint>\"") | ||
| exit() | ||
|
|
||
|
|
||
| default_credential = DefaultAzureCredential() | ||
| # Define the scope for Azure Resource Manager (ARM) | ||
| arm_scope = "https://durabletask.io/.default" | ||
|
|
||
| # Retrieve the access token | ||
| access_token = "Bearer " + default_credential.get_token(arm_scope).token | ||
RyanLettieri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # create a client, start an orchestration, and wait for it to finish | ||
| metaData: list[tuple[str, str]] = [ | ||
| ("taskhub", taskhub_name), # Hardcode for now, just the taskhub name | ||
RyanLettieri marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ("authorization", access_token) # use azure identity sdk for python | ||
| ] | ||
| # configure and start the worker | ||
| with worker.TaskHubGrpcWorker(host_address=endpoint, metadata=metaData, secure_channel=True) as w: | ||
| w.add_orchestrator(sequence) | ||
| w.add_activity(hello) | ||
| w.start() | ||
|
|
||
| c = client.TaskHubGrpcClient(host_address=endpoint, metadata=metaData, secure_channel=True) | ||
| instance_id = c.schedule_new_orchestration(sequence) | ||
| state = c.wait_for_orchestration_completion(instance_id, timeout=45) | ||
| if state and state.runtime_status == client.OrchestrationStatus.COMPLETED: | ||
| print(f'Orchestration completed! Result: {state.serialized_output}') | ||
| elif state: | ||
| print(f'Orchestration failed: {state.failure_details}') | ||
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.
Uh oh!
There was an error while loading. Please reload this page.