forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstarter.py
More file actions
57 lines (43 loc) · 1.44 KB
/
starter.py
File metadata and controls
57 lines (43 loc) · 1.44 KB
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
52
53
54
55
56
57
#!/usr/bin/env python3
"""Starter for the batch iterator sample."""
import asyncio
import datetime
import logging
from temporalio.client import Client
from batch_iterator.shared import ProcessBatchInput
from batch_iterator.workflows import IteratorBatchWorkflow
async def main():
"""Start the IteratorBatchWorkflow."""
# Set up logging
logging.basicConfig(level=logging.INFO)
# Create client
client = await Client.connect("localhost:7233")
# Create unique workflow ID with timestamp
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
workflow_id = f"batch_iterator_example_{timestamp}"
# Define workflow input
workflow_input = ProcessBatchInput(
record_count=100,
page_size=10,
)
print(f"Starting workflow with ID: {workflow_id}")
print(f"Input: {workflow_input}")
# Start workflow
handle = await client.start_workflow(
IteratorBatchWorkflow.run,
workflow_input,
id=workflow_id,
task_queue="batch_iterator_task_queue",
)
print(f"Workflow started with ID: {handle.id}")
print(f"Waiting for workflow to complete...")
# Wait for result
try:
result = await handle.result()
print(f"Workflow completed successfully!")
print(f"Total records processed: {result}")
except Exception as e:
print(f"Workflow failed with error: {e}")
raise
if __name__ == "__main__":
asyncio.run(main())