forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.py
More file actions
39 lines (28 loc) · 1006 Bytes
/
worker.py
File metadata and controls
39 lines (28 loc) · 1006 Bytes
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
#!/usr/bin/env python3
"""Worker for the batch iterator sample."""
import asyncio
import logging
from temporalio import worker
from temporalio.client import Client
from batch_iterator.activities import get_records
from batch_iterator.workflows import IteratorBatchWorkflow, RecordProcessorWorkflow
async def main():
"""Run the worker that registers workflows and activities."""
# Set up logging
logging.basicConfig(level=logging.INFO)
# Create client
client = await Client.connect("localhost:7233")
# Create worker
temporal_worker = worker.Worker(
client,
task_queue="batch_iterator_task_queue",
workflows=[IteratorBatchWorkflow, RecordProcessorWorkflow],
activities=[get_records],
)
print("Starting worker for batch iterator...")
print("Worker will process workflows and activities")
print("Press Ctrl+C to stop")
# Run the worker
await temporal_worker.run()
if __name__ == "__main__":
asyncio.run(main())