77from temporalio .exceptions import ApplicationError
88
99from batch_sliding_window .record_loader_activity import RecordLoader
10- from batch_sliding_window .sliding_window_workflow import SlidingWindowWorkflow , SlidingWindowWorkflowInput
10+ from batch_sliding_window .sliding_window_workflow import (
11+ SlidingWindowWorkflow ,
12+ SlidingWindowWorkflowInput ,
13+ )
1114
1215
1316@dataclass
1417class ProcessBatchWorkflowInput :
1518 """Input for the ProcessBatchWorkflow.
16-
17- A single input structure is preferred to multiple workflow arguments
19+
20+ A single input structure is preferred to multiple workflow arguments
1821 to simplify backward compatible API changes.
1922 """
23+
2024 page_size : int # Number of children started by a single sliding window workflow run
2125 sliding_window_size : int # Maximum number of children to run in parallel
2226 partitions : int # How many sliding windows to run in parallel
@@ -25,8 +29,8 @@ class ProcessBatchWorkflowInput:
2529@workflow .defn
2630class ProcessBatchWorkflow :
2731 """Sample workflow that partitions the data set into continuous ranges.
28-
29- A real application can choose any other way to divide the records
32+
33+ A real application can choose any other way to divide the records
3034 into multiple collections.
3135 """
3236
@@ -44,7 +48,9 @@ async def run(self, input: ProcessBatchWorkflowInput) -> int:
4448 )
4549
4650 partitions = self ._divide_into_partitions (record_count , input .partitions )
47- window_sizes = self ._divide_into_partitions (input .sliding_window_size , input .partitions )
51+ window_sizes = self ._divide_into_partitions (
52+ input .sliding_window_size , input .partitions
53+ )
4854
4955 workflow .logger .info (
5056 f"ProcessBatchWorkflow started" ,
@@ -53,22 +59,22 @@ async def run(self, input: ProcessBatchWorkflowInput) -> int:
5359 "record_count" : record_count ,
5460 "partitions" : partitions ,
5561 "window_sizes" : window_sizes ,
56- }
62+ },
5763 )
5864
5965 # Start child workflows for each partition
6066 tasks = []
6167 offset = 0
62-
68+
6369 for i in range (input .partitions ):
6470 # Make child id more user-friendly
6571 child_id = f"{ workflow .info ().workflow_id } /{ i } "
66-
72+
6773 # Define partition boundaries
6874 maximum_partition_offset = offset + partitions [i ]
6975 if maximum_partition_offset > record_count :
7076 maximum_partition_offset = record_count
71-
77+
7278 child_input = SlidingWindowWorkflowInput (
7379 page_size = input .page_size ,
7480 sliding_window_size = window_sizes [i ],
@@ -77,7 +83,7 @@ async def run(self, input: ProcessBatchWorkflowInput) -> int:
7783 progress = 0 ,
7884 current_records = None ,
7985 )
80-
86+
8187 task = workflow .execute_child_workflow (
8288 SlidingWindowWorkflow .run ,
8389 child_input ,
@@ -100,4 +106,4 @@ def _divide_into_partitions(self, number: int, n: int) -> List[int]:
100106 for i in range (remainder ):
101107 partitions [i ] += 1
102108
103- return partitions
109+ return partitions
0 commit comments