Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
d3ac21a
Initial draft for python SDK
RyanLettieri Apr 18, 2023
575bba0
Merge branch 'master' of https://github.com/dapr/python-sdk into work…
RyanLettieri Apr 18, 2023
9acdf2c
Adding workflow code to aio client
RyanLettieri Apr 18, 2023
3e23139
Fixing protos and small fixes to workflow imports
RyanLettieri Apr 18, 2023
c4e9ef7
Workflow Authoring
DeepanshuA Apr 25, 2023
487e97f
Add example
DeepanshuA Apr 25, 2023
0733570
Merge branch 'master' of github.com:dapr/python-sdk into workflow_aut…
DeepanshuA Apr 25, 2023
26380ee
lint
DeepanshuA Apr 25, 2023
eb995b8
is it wheel fix
DeepanshuA Apr 25, 2023
cd044d1
fix lint
DeepanshuA Apr 25, 2023
6fde40c
Updating proto and more small fixes to workflow
RyanLettieri Apr 27, 2023
128a1fa
Add tests and client APIs
DeepanshuA Apr 27, 2023
e074e58
Updating proto and merging in other changes
RyanLettieri Apr 27, 2023
2682d72
Updating proto
RyanLettieri Apr 27, 2023
9361b30
lint
DeepanshuA Apr 27, 2023
49c78d7
Removing super init
RyanLettieri Apr 28, 2023
0516400
tox fix
RyanLettieri Apr 28, 2023
f82bb8e
Merge branch 'master' of github.com:dapr/python-sdk into workflow_aut…
DeepanshuA Apr 28, 2023
ffde1df
Add dtf python dependency
DeepanshuA Apr 28, 2023
8d62488
correction
DeepanshuA Apr 28, 2023
28690f0
Some implementation of workflow into fake server and other cleanup
RyanLettieri Apr 30, 2023
3015073
Fixing input for workflow
RyanLettieri Apr 30, 2023
de23696
More workflow cleanup
RyanLettieri Apr 30, 2023
15938b4
Fixing up workflow options to be optional
RyanLettieri May 1, 2023
19ea43f
Few more updates to workflow
RyanLettieri May 2, 2023
40fe904
Few more updates to workflow merging
RyanLettieri May 2, 2023
1be2447
Remove get-pip.py
DeepanshuA May 2, 2023
ab2d201
Updating examples test for workflow and cleaning up methods
RyanLettieri May 2, 2023
a537862
Update durabletask dependency version
DeepanshuA May 2, 2023
75ae2bf
Extra line - to be deleted
DeepanshuA May 3, 2023
7a31c66
test compatible with 3.7
DeepanshuA May 3, 2023
3c11d6c
Fixing comment
RyanLettieri May 3, 2023
f5c7796
Merge branch 'master' of https://github.com/dapr/python-sdk into work…
RyanLettieri May 3, 2023
325dedb
Merge branch 'master' into workflow_authoring
yaron2 May 4, 2023
b8bca56
Merge branch 'master' of github.com:dapr/python-sdk into workflow_aut…
DeepanshuA May 9, 2023
2f81812
Incorporate review comments
DeepanshuA May 10, 2023
3185586
Merge branch 'workflow_authoring' of https://github.com/DeepanshuA/py…
DeepanshuA May 10, 2023
2ff152e
lint
DeepanshuA May 11, 2023
347c0bf
Ut fix
DeepanshuA May 11, 2023
2ebf20c
validate demo_workflow
DeepanshuA May 11, 2023
a8fa501
App Readme
DeepanshuA May 11, 2023
05194c8
fix step md
DeepanshuA May 11, 2023
b2aff5c
Adding in exceptions to workflow methods
RyanLettieri May 11, 2023
cc25bd7
Encoding workflow start data and fixing test
RyanLettieri May 11, 2023
1a8af1d
Cleaning up some workflow methods
RyanLettieri May 11, 2023
7598dd1
Validate demo workflow example
DeepanshuA May 12, 2023
74dbc9f
Remove demo actor temporarily
DeepanshuA May 12, 2023
bf69dea
Include raise event test and assertions
DeepanshuA May 16, 2023
0968b8e
Rename
DeepanshuA May 16, 2023
94f915b
Adressing some workflow comments
RyanLettieri May 17, 2023
4886c9e
Incorporate Review comments
DeepanshuA May 18, 2023
18bc883
Lint, validate
DeepanshuA May 18, 2023
9d8ec7f
test correction
DeepanshuA May 18, 2023
49f960a
Fake class method correction
DeepanshuA May 18, 2023
c64a091
Check expected std output in validate example
DeepanshuA May 18, 2023
f3207fc
Remove extra port check
DeepanshuA May 19, 2023
2bfc44a
Merge branch 'master' of github.com:dapr/python-sdk into workflow_aut…
DeepanshuA May 19, 2023
82b33e5
Temporary - Verify Workflow Example first
DeepanshuA May 19, 2023
de33a9b
Requirements
DeepanshuA May 19, 2023
363a0df
Remove line
DeepanshuA May 19, 2023
ba2087a
Add back removed validate examples
DeepanshuA May 19, 2023
a3fb750
Update examples/demo_workflow/demo_workflow/requirements.txt
berndverst May 22, 2023
135d3d7
Change running order of wf
DeepanshuA May 22, 2023
a9be483
Commit to re-run example
DeepanshuA May 22, 2023
0e0203d
Merge branch 'master' of https://github.com/dapr/python-sdk into work…
RyanLettieri May 22, 2023
003e25b
Merging in authoring for workflow
RyanLettieri May 23, 2023
b9865b3
Merging in master
RyanLettieri May 23, 2023
0a0e94b
Addressing some review comments
RyanLettieri May 23, 2023
23ae6f7
Few updates for workflow PR
RyanLettieri May 24, 2023
9cc7e4a
More workflow PR fixes
RyanLettieri May 24, 2023
30ab277
Merge branch 'master' into workflow-sdk
RyanLettieri May 24, 2023
da401e8
More workflow typing fixes
RyanLettieri May 25, 2023
8b7dec9
Merge branch 'workflow-sdk' of https://github.com/RyanLettieri/python…
RyanLettieri May 25, 2023
e1d050c
Test and aio client fixes for workflow
RyanLettieri May 25, 2023
d7e9ebd
Whitespace fix
RyanLettieri May 25, 2023
9f5f138
Making workflow test more deterministic
RyanLettieri May 25, 2023
d08907e
Fixing broken workflow test
RyanLettieri May 26, 2023
722e5b3
Addressing some workflow comments
RyanLettieri May 26, 2023
57af017
linting
RyanLettieri May 26, 2023
40da262
Addressing more comments
RyanLettieri May 29, 2023
4c985f0
Even more fixes to workflow
RyanLettieri May 29, 2023
a4769d5
Fixing workflow example
RyanLettieri May 29, 2023
cbed6a2
Making workflow example more consitent
RyanLettieri May 29, 2023
739f145
Making workflow example more consitent again
RyanLettieri May 29, 2023
6932f97
Merging in master
RyanLettieri May 30, 2023
9c6ae6f
Fixing serialization on workflow
RyanLettieri May 30, 2023
efd8420
Code formatting for workflow
RyanLettieri May 30, 2023
ff513f2
Updating workflow documentation
RyanLettieri May 30, 2023
04be191
Fixing input to start workflow
RyanLettieri May 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 210 additions & 0 deletions dapr/aio/clients/grpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,216 @@ async def unlock(
return UnlockResponse(status=UnlockResponseStatus(response.status),
headers=await call.initial_metadata())

async def start_workflow(
self,
instance_id: str,
workflow_component: str,
workflow_name: str,
input: bytes,
Comment thread
RyanLettieri marked this conversation as resolved.
Outdated
workflow_options: dict) -> api_v1.StartWorkflowResponse:
"""Starts a workflow.
Args:
instance_id (str): the name of the workflow instance,
e.g. `order_processing_workflow-103784`.
workflow_component (str): the name of the workflow component
that will run the workflow. e.g. `dapr`.
workflow_name (str): the name of the workflow that will be executed.
input (bytes): the input that the workflow will receive.
workflow_options (dict): the key-value options that the workflow will receive.
Comment thread
RyanLettieri marked this conversation as resolved.
Outdated
Returns:
:class:`StartWorkflowResponse`: Instance ID associated with the started workflow
"""
# Warnings and input validation
warn('The Workflow API is an Alpha version and is subject to change.',
UserWarning, stacklevel=2)
validateNotBlankString(instance_id=instance_id,
workflow_component=workflow_component,
workflow_name=workflow_name)
# Actual start workflow invocation
req = api_v1.StartWorkflowRequest(
instance_id=instance_id,
workflow_component=workflow_component,
workflow_name=workflow_name,
options=workflow_options,
input=input)
response, call = self._stub.StartWorkflowAlpha1.with_call(req)

return api_v1.StartWorkflowResponse(instance_id=response.instanceID,
workflow_component=response.workflowComponent,
workflow_name=response.workflowName)

# RRL TODO: Clean up return obkect
async def get_workflow(
self,
instance_id: str,
workflow_component: str) -> api_v1.GetWorkflowResponse:
"""Gets information on a workflow.

Args:
instance_id (str): the name of the workflow instance,
e.g. `order_processing_workflow-103784`.
workflow_component (str): the name of the workflow component
that will run the workflow. e.g. `dapr`.

Returns:
:class:`GetWorkflowResponse`: Status of the request,
`UnlockResponseStatus.success` if it was successful of some other
status otherwise.
"""
# Warnings and input validation
warn('The Workflow API is an Alpha version and is subject to change.',
UserWarning, stacklevel=2)
validateNotBlankString(instance_id=instance_id,
workflow_component=workflow_component)
# Actual get workflow invocation
req = api_v1.GetWorkflowRequest(
instance_id=instance_id,
workflow_component=workflow_component)
response, call = self._stub.GetWorkflowAlpha1.with_call(req)

# RRL TODO: Fix this
return api_v1.GetWorkflowResponse(instance_id=instance_id,
workflow_name=response.workflow_name,
created_at=response.created_at,
last_updated_at=response.last_updated_at,
runtime_status=response.runtime_status)

async def terminate_workflow(
self,
instance_id: str,
workflow_component: str) -> DaprResponse:
"""Terminates a workflow.
Args:
instance_id (str): the name of the workflow instance, e.g.
`order_processing_workflow-103784`.
workflow_component (str): the name of the workflow component
that will run the workflow. e.g. `dapr`.
Returns:
:class:`DaprResponse` gRPC metadata returned from callee
"""
# Warnings and input validation
warn('The Workflow API is an Alpha version and is subject to change.',
UserWarning, stacklevel=2)
validateNotBlankString(instance_id=instance_id,
workflow_component=workflow_component)
# Actual terminate workflow invocation
req = api_v1.TerminateWorkflowRequest(
instance_id=instance_id,
workflow_component=workflow_component)
_, call = self._stub.TerminateWorkflowAlpha1.with_call(req)

return DaprResponse(
headers=call.initial_metadata())

# RRL TODO: Clean up return obkect comments
async def raise_event(
self,
instance_id: str,
workflow_component: str) -> DaprResponse:
"""Raises an event on a workflow.
Args:
instance_id (str): the name of the workflow instance,
Comment thread
RyanLettieri marked this conversation as resolved.
Outdated
e.g. `order_processing_workflow-103784`.
workflow_component (str): the name of the workflow component
that will run the workflow. e.g. `dapr`.
Returns:
:class:`DaprResponse` gRPC metadata returned from callee
"""
# Warnings and input validation
warn('The Workflow API is an Alpha version and is subject to change.',
UserWarning, stacklevel=2)
validateNotBlankString(instance_id=instance_id,
workflow_component=workflow_component)
# Actual terminate workflow invocation
Comment thread
RyanLettieri marked this conversation as resolved.
Outdated
req = api_v1.TerminateWorkflowRequest(
instance_id=instance_id,
workflow_component=workflow_component)
_, call = self._stub.TerminateWorkflowAlpha1.with_call(req)

return DaprResponse(
headers=call.initial_metadata())

async def pause_workflow(
self,
instance_id: str,
workflow_component: str) -> DaprResponse:
"""Pause a workflow.
Args:
instance_id (str): the name of the workflow instance,
e.g. `order_processing_workflow-103784`.
workflow_component (str): the name of the workflow component
that will run the workflow. e.g. `dapr`.
Returns:
:class:`DaprResponse` gRPC metadata returned from callee
"""
# Warnings and input validation
warn('The Workflow API is an Alpha version and is subject to change.',
UserWarning, stacklevel=2)
validateNotBlankString(instance_id=instance_id,
workflow_component=workflow_component)
# Actual pause workflow invocation
req = api_v1.PauseWorkflowRequest(
instance_id=instance_id,
workflow_component=workflow_component)
_, call = self._stub.PauseWorkflowAlpha1.with_call(req)

return DaprResponse(
headers=call.initial_metadata())

async def resume_workflow(
self,
instance_id: str,
workflow_component: str) -> DaprResponse:
"""Resumes a workflow.
Args:
instance_id (str): the name of the workflow instance,
e.g. `order_processing_workflow-103784`.
workflow_component (str): the name of the workflow component
that will run the workflow. e.g. `dapr`.
Returns:
:class:`DaprResponse` gRPC metadata returned from callee
"""
# Warnings and input validation
warn('The Workflow API is an Alpha version and is subject to change.',
UserWarning, stacklevel=2)
validateNotBlankString(instance_id=instance_id,
workflow_component=workflow_component)
# Actual resume workflow invocation
req = api_v1.ResumeWorkflowRequest(
instance_id=instance_id,
workflow_component=workflow_component)
_, call = self._stub.ResumeWorkflowAlpha1.with_call(req)

return DaprResponse(
headers=call.initial_metadata())

async def purge_workflow(
self,
instance_id: str,
workflow_component: str) -> DaprResponse:
"""Purges a workflow.
Args:
instance_id (str): the name of the workflow instance,
e.g. `order_processing_workflow-103784`.
workflow_component (str): the name of the workflow component
that will run the workflow. e.g. `dapr`.
Returns:
:class:`DaprResponse` gRPC metadata returned from callee
"""
# Warnings and input validation
warn('The Workflow API is an Alpha version and is subject to change.',
UserWarning, stacklevel=2)
validateNotBlankString(instance_id=instance_id,
workflow_component=workflow_component)
# Actual purge workflow invocation
req = api_v1.PurgeWorkflowRequest(
instance_id=instance_id,
workflow_component=workflow_component)
_, call = self._stub.PurgeWorkflowAlpha1.with_call(req)

return DaprResponse(
headers=call.initial_metadata())

async def wait(self, timeout_s: float):
"""Waits for sidecar to be available within the timeout.

Expand Down
58 changes: 58 additions & 0 deletions dapr/clients/grpc/_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,64 @@ def extended_metadata(self) -> Dict[str, str]:
return self._extended_metadata


# RRL TODO: Add properties and fix init
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix or remove in this PR

class GetWorkflowResponse():
'''The response of get_workflow operation.'''

def __init__(
self,
client: DaprGrpcClient,
instance_id: str,
workflow_name: str,
created_at: str,
last_updated_at: str,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both created_at and last_updated_at should be datetime, not str.

runtime_status: str,
Comment thread
RyanLettieri marked this conversation as resolved.
Outdated
properties: Dict[str, str] = {},
headers: MetadataTuple = (),
):
"""Initializes a GetWorkflowResponse.

Args:
client (DaprClient): a reference to the dapr client used for the GetWorkflow request.
instance_id (str): the instance ID assocated with this response.
workflow_name (str): the name of the workflow that was started.
created_at (str): the time at which the workflow started executing.
last_updated_at (str): the time at which the workflow was last updated.
runtime_status (str): the current runtime status of the workflow.
properties (Dict[str, str]): properties sent as a reponse by the workflow.
headers (Tuple, optional): the headers from Dapr gRPC response.
"""
super().__init__(headers)
Comment thread
RyanLettieri marked this conversation as resolved.
Outdated
self._client = client
self._instance_id = instance_id
self._workflow_name = workflow_name
self._created_at = created_at
self._last_updated_at = last_updated_at
self._runtime_status = runtime_status
self._properties = properties


class StartWorkflowResponse():
'''The response of start_workflow operation.'''

def __init__(
self,
instance_id: str,
client: DaprGrpcClient,
headers: MetadataTuple = (),
):
"""Initializes a StartWorkflowResponse.

Args:
instance_id (str): the instance ID assocated with this response.
client (DaprClient): a reference to the dapr client used for the GetWorkflow request.
headers (Tuple, optional): the headers from Dapr gRPC response.
"""
super().__init__(headers)
Comment thread
RyanLettieri marked this conversation as resolved.
Outdated
self.instance_id = instance_id
Comment on lines +968 to +980
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that a NamedTuple could have worked just fine here, specially because it would get it being read-only (which I guess instance_id should be) for free.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dataclass is another option, though I see that we already used NamedTuple in this codebase.

self._client = client


class RegisteredComponents(NamedTuple):
'''Describes a loaded Dapr component.'''

Expand Down
Loading