/
wf_query_dacx.py
51 lines (37 loc) · 1.21 KB
/
wf_query_dacx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import asyncio
from temporalio import workflow
"""dacx
To define a Query, set the Query decorator [`@workflow.query`](https://python.temporal.io/temporalio.workflow.html#query) on the Query function inside your Workflow.
**Customize names**
You can have a name parameter to customize the Query's name, otherwise it defaults to the name of the Query method.
:::note
You can either set the `name` or the `dynamic` parameter in a Query's decorator, but not both.
:::
dacx"""
@workflow.defn
class GreetingWorkflow:
def __init__(self) -> None:
self._greeting = "<no greeting>"
@workflow.run
async def run(self, name: str) -> None:
self._greeting = f"Hello, {name}!"
await asyncio.sleep(2)
self._greeting = f"Goodbye, {name}!"
@workflow.query
def greeting(self) -> str:
return self._greeting
@workflow.query(name="Custom Query Name")
def custom_greeting(self) -> str:
return self._greeting
""" @dacx
id: how-to-define-a-query-in-python
title: How to define a Query in Python
label: Define a Query
description: Use the `@workflow.query` decorator to define a Query.
tags:
- query
- workflow
- python sdk
- code sample
lines: 5-17, 31-33
@dacx """