14
14
* limitations under the License.
15
15
*/
16
16
package io .lenses .streamreactor .connect .cloud .common .source .files
17
+
17
18
import cats .implicits .catsSyntaxEitherId
18
19
import cats .implicits .catsSyntaxOptionId
19
20
import cats .implicits .toShow
20
21
import com .typesafe .scalalogging .LazyLogging
21
22
import io .lenses .streamreactor .connect .cloud .common .config .ConnectorTaskId
22
23
import io .lenses .streamreactor .connect .cloud .common .model .location .CloudLocation
23
24
import io .lenses .streamreactor .connect .cloud .common .model .location .CloudLocationValidator
24
- import io .lenses .streamreactor .connect .cloud .common .source .config .PostProcessAction
25
25
import io .lenses .streamreactor .connect .cloud .common .storage .FileListError
26
26
import io .lenses .streamreactor .connect .cloud .common .storage .FileMetadata
27
27
import io .lenses .streamreactor .connect .cloud .common .storage .ListOfKeysResponse
@@ -32,14 +32,6 @@ trait SourceFileQueue {
32
32
def next (): Either [FileListError , Option [CloudLocation ]]
33
33
}
34
34
35
- /**
36
- * A tracker for the last seen file.
37
- *
38
- * @param lastSeenFile An optional metadata object representing the last seen file.
39
- * @tparam SM The type of the file metadata.
40
- */
41
- case class LastSeenFileTracker [SM <: FileMetadata ](var lastSeenFile : Option [SM ])
42
-
43
35
/**
44
36
* Blocking processor for queues of operations. Used to ensure consistency.
45
37
* Will block any further writes by the current file until the remote has caught up.
@@ -57,7 +49,7 @@ class CloudSourceFileQueue[SM <: FileMetadata] private (
57
49
* files will be cleaned up after processing, removing the need to track the last seen file.
58
50
* In such cases, this parameter will be None.
59
51
*/
60
- private var lastSeenFileTracker : Option [LastSeenFileTracker [ SM ] ],
52
+ private var lastSeenFile : Option [SM ],
61
53
)(
62
54
implicit
63
55
cloudLocationValidator : CloudLocationValidator ,
@@ -70,7 +62,7 @@ class CloudSourceFileQueue[SM <: FileMetadata] private (
70
62
)(
71
63
implicit
72
64
cloudLocationValidator : CloudLocationValidator ,
73
- ) = this (taskId, batchListerFn, Seq .empty, Some ( LastSeenFileTracker [ SM ]( None )) )
65
+ ) = this (taskId, batchListerFn, Seq .empty, None )
74
66
75
67
override def next (): Either [FileListError , Option [CloudLocation ]] =
76
68
files match {
@@ -90,11 +82,10 @@ class CloudSourceFileQueue[SM <: FileMetadata] private (
90
82
91
83
private def retrieveNextFile (
92
84
): Either [FileListError , Option [CloudLocation ]] = {
93
- val nextBatch : Either [FileListError , Option [ListResponse [String , SM ]]] =
94
- batchListerFn(lastSeenFileTracker.flatMap(_.lastSeenFile))
85
+ val nextBatch : Either [FileListError , Option [ListResponse [String , SM ]]] = batchListerFn(lastSeenFile)
95
86
nextBatch.flatMap {
96
87
case Some (ListOfKeysResponse (bucket, prefix, value, meta)) =>
97
- lastSeenFileTracker = lastSeenFileTracker.map(_.copy( lastSeenFile = meta.some))
88
+ lastSeenFile = meta.some
98
89
files = value.map(path =>
99
90
CloudLocation (
100
91
bucket,
@@ -116,11 +107,10 @@ class CloudSourceFileQueue[SM <: FileMetadata] private (
116
107
117
108
object CloudSourceFileQueue {
118
109
def from [SM <: FileMetadata ](
119
- batchListerFn : Option [SM ] => Either [FileListError , Option [ListOfKeysResponse [SM ]]],
120
- storageInterface : StorageInterface [SM ],
121
- startingFile : CloudLocation ,
122
- taskId : ConnectorTaskId ,
123
- maybePostProcessAction : Option [PostProcessAction ],
110
+ batchListerFn : Option [SM ] => Either [FileListError , Option [ListOfKeysResponse [SM ]]],
111
+ storageInterface : StorageInterface [SM ],
112
+ startingFile : CloudLocation ,
113
+ taskId : ConnectorTaskId ,
124
114
)(
125
115
implicit
126
116
cloudLocationValidator : CloudLocationValidator ,
@@ -133,15 +123,7 @@ object CloudSourceFileQueue {
133
123
case _ =>
134
124
Option .empty[SM ]
135
125
}
136
- new CloudSourceFileQueue [SM ](
137
- taskId,
138
- batchListerFn,
139
- Seq (startingFile),
140
- // Creates an instance of LastSeenFileTracker if no PostProcessAction is set
141
- // If PostProcessAction is set then files will be cleaned up after processing,
142
- // which removes the requirement to seek through to the last seen file.
143
- Option .when(maybePostProcessAction.isEmpty)(LastSeenFileTracker [SM ](lastSeen)),
144
- )
126
+ new CloudSourceFileQueue (taskId, batchListerFn, Seq (startingFile), lastSeen)
145
127
}
146
128
147
129
}
0 commit comments