@@ -96,13 +96,12 @@ def on_partition(self, partition: Partition) -> None:
9696 """
9797 stream_name = partition .stream_name ()
9898 self ._streams_to_running_partitions [stream_name ].add (partition )
99- cursor = self ._stream_name_to_instance [stream_name ].cursor
10099 if self ._slice_logger .should_log_slice_message (self ._logger ):
101100 self ._message_repository .emit_message (
102101 self ._slice_logger .create_slice_log_message (partition .to_slice ())
103102 )
104103 self ._thread_pool_manager .submit (
105- self ._partition_reader .process_partition , partition , cursor
104+ self ._partition_reader .process_partition , partition
106105 )
107106
108107 def on_partition_complete_sentinel (
@@ -116,16 +115,26 @@ def on_partition_complete_sentinel(
116115 """
117116 partition = sentinel .partition
118117
119- partitions_running = self ._streams_to_running_partitions [partition .stream_name ()]
120- if partition in partitions_running :
121- partitions_running .remove (partition )
122- # If all partitions were generated and this was the last one, the stream is done
123- if (
124- partition .stream_name () not in self ._streams_currently_generating_partitions
125- and len (partitions_running ) == 0
126- ):
127- yield from self ._on_stream_is_done (partition .stream_name ())
128- yield from self ._message_repository .consume_queue ()
118+ try :
119+ if sentinel .is_successful :
120+ stream = self ._stream_name_to_instance [partition .stream_name ()]
121+ stream .cursor .close_partition (partition )
122+ except Exception as exception :
123+ self ._flag_exception (partition .stream_name (), exception )
124+ yield AirbyteTracedException .from_exception (
125+ exception , stream_descriptor = StreamDescriptor (name = partition .stream_name ())
126+ ).as_sanitized_airbyte_message ()
127+ finally :
128+ partitions_running = self ._streams_to_running_partitions [partition .stream_name ()]
129+ if partition in partitions_running :
130+ partitions_running .remove (partition )
131+ # If all partitions were generated and this was the last one, the stream is done
132+ if (
133+ partition .stream_name () not in self ._streams_currently_generating_partitions
134+ and len (partitions_running ) == 0
135+ ):
136+ yield from self ._on_stream_is_done (partition .stream_name ())
137+ yield from self ._message_repository .consume_queue ()
129138
130139 def on_record (self , record : Record ) -> Iterable [AirbyteMessage ]:
131140 """
@@ -154,6 +163,7 @@ def on_record(self, record: Record) -> Iterable[AirbyteMessage]:
154163 stream .as_airbyte_stream (), AirbyteStreamStatus .RUNNING
155164 )
156165 self ._record_counter [stream .name ] += 1
166+ stream .cursor .observe (record )
157167 yield message
158168 yield from self ._message_repository .consume_queue ()
159169
0 commit comments