Registry Mirror
搜索
Skip to content
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Files
Expand file tree
main
Breadcrumbs
examples
/
python
/
patterns-use-cases
/
syncasync
/
client.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
39 lines (29 loc) · 1.16 KB
main
Breadcrumbs
examples
/
python
/
patterns-use-cases
/
syncasync
/
client.py
Copy path
Top
File metadata and controls
Code
Blame
39 lines (29 loc) · 1.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import argparse
import logging
import httpx
logging.basicConfig(
level=logging.INFO,
format="[%(asctime)s] [%(process)d] [%(levelname)s] - %(message)s",
)
logger = logging.getLogger(__name__)
RESTATE_URL = "http://localhost:8080"
# The upload client calls the data upload workflow and awaits the result for 5 seconds.
# If the workflow doesn't complete within that time, it asks the
# workflow to send the upload url via email instead.
def upload_data(id: str, email: str):
logging.info(f"Start upload for {id}")
try:
url = f"{RESTATE_URL}/DataUploadService/{id}/run"
upload_url = httpx.post(url, timeout=5).json()
except httpx.RequestError:
logging.info("Slow upload... Mail the link later")
email_url = f"{RESTATE_URL}/DataUploadService/{id}/resultAsEmail/send"
httpx.post(email_url, json=email)
return
# ... process result directly ...
logging.info(f"Fast upload: URL was {upload_url}")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("id", type=str, help="User ID")
args = parser.parse_args()
upload_data(id=args.id, email=f"{args.id}@example.com")
You can’t perform that action at this time.