Skip to content

Commit b28f360

Browse files
committed
Move Propulsion.Feed.Batch up a level
1 parent 13b02e2 commit b28f360

File tree

15 files changed

+33
-39
lines changed

15 files changed

+33
-39
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ The `Unreleased` section name is replaced by the expected version of next releas
5252
- `Propulsion.CosmosStore.CosmosStoreSink`+`CosmosStorePruner`: Exposed `*Stats` [#226](https://github.com/jet/propulsion/pull/226)
5353
- `Propulsion.EventStore`: Pinned to target `Equinox.EventStore` v `[3.0.7`-`3.99.0]` **Deprecated; Please migrate to `Propulsion.EventStoreDb`** [#139](https://github.com/jet/propulsion/pull/139)
5454
- `Propulsion.EventStoreDb.EventStoreSource`: Changed API to match`Propulsion.SqlStreamStore` API rather than`Propulsion.EventStore` [#139](https://github.com/jet/propulsion/pull/139)
55-
- `Propulsion.Feed`: Moved implementations into main `Propulsion` library. While this adds a `FSharp.Control.TaskSeq` dependency, it makes maintenance and navigation easier
55+
- `Propulsion.Feed`: Moved implementations into main `Propulsion` library. While this adds a `FSharp.Control.TaskSeq` dependency, it makes maintenance and navigation easier [#265](https://github.com/jet/propulsion/pull/265)
5656
- `Propulsion.Feed`,`Kafka`: Replaced `Async` with `task` for supervision [#158](https://github.com/jet/propulsion/pull/158), [#159](https://github.com/jet/propulsion/pull/159)
5757
- `Propulsion.Kafka`: Target `FsCodec.NewtonsoftJson` v `3.0.0` [#139](https://github.com/jet/propulsion/pull/139)
58-
- `Propulsion.Prometheus`: Extracted `Propulsion.Prometheus` and `Propulsion.Feed.Prometheus` in order to remove `Prometheus` dependency from core package
58+
- `Propulsion.Prometheus`: Extracted `Propulsion.Prometheus` and `Propulsion.Feed.Prometheus` in order to remove `Prometheus` dependency from core package [#265](https://github.com/jet/propulsion/pull/265)
5959
- `Propulsion.Tool`: `project` renamed to `sync`; sources now have a `from` prefix [#252](https://github.com/jet/propulsion/pull/252)
6060

6161
### Removed

src/Propulsion.DynamoStore/DynamoStoreSource.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module private Impl =
3232
| Exceptions.ProvisionedThroughputExceeded when not force -> ()
3333
| e -> storeLog.Warning(e, "DynamoStoreSource commit failure")
3434

35-
let mkBatch position isTail items: Propulsion.Feed.Core.Batch<Propulsion.Sinks.EventBody> =
35+
let mkBatch position isTail items: Propulsion.Feed.Batch<Propulsion.Sinks.EventBody> =
3636
{ items = items; checkpoint = position; isTail = isTail }
3737
let sliceBatch epochId offset items =
3838
mkBatch (Checkpoint.positionOfEpochAndOffset epochId offset) false items

src/Propulsion.EventStoreDb/EventStoreSource.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module private Impl =
1717
let pos = let p = pos |> Propulsion.Feed.Position.toInt64 |> uint64 in Position(p, p)
1818
let res = store.ReadAllAsync(Direction.Forwards, pos, batchSize, withData, cancellationToken = ct)
1919
let! batch = res |> TaskSeq.map _.Event |> TaskSeq.toArrayAsync
20-
return ({ checkpoint = checkpointPos batch; items = toItems streamFilter batch; isTail = batch.LongLength <> batchSize }: Propulsion.Feed.Core.Batch<_>) }
20+
return ({ checkpoint = checkpointPos batch; items = toItems streamFilter batch; isTail = batch.LongLength <> batchSize }: Propulsion.Feed.Batch<_>) }
2121

2222
// @scarvel8: event_global_position = 256 x 1024 x 1024 x chunk_number + chunk_header_size (128) + event_position_offset_in_chunk
2323
let private chunk (pos: Position) = uint64 pos.CommitPosition >>> 28

src/Propulsion.MessageDb/MessageDbSource.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ module Internal =
5353
let sn = reader.GetString(6) |> FsCodec.StreamName.parse
5454
struct (sn, event)
5555

56-
member _.ReadCategoryMessages(category: TrancheId, fromPositionInclusive: int64, batchSize: int, ct): Task<Core.Batch<_>> = task {
56+
member _.ReadCategoryMessages(category: TrancheId, fromPositionInclusive: int64, batchSize: int, ct): Task<Batch<_>> = task {
5757
use! conn = connect ct
5858
use command = GetCategoryMessages.prepareCommand conn category fromPositionInclusive batchSize
5959

6060
use! reader = command.ExecuteReaderAsync(ct)
6161
let events = [| while reader.Read() do parseRow reader |]
6262

6363
let checkpoint = match Array.tryLast events with Some (_, ev) -> unbox<int64> ev.Context | None -> fromPositionInclusive
64-
return ({ checkpoint = Position.parse checkpoint; items = events; isTail = events.Length = 0 }: Core.Batch<_>) }
64+
return ({ checkpoint = Position.parse checkpoint; items = events; isTail = events.Length = 0 }: Batch<_>) }
6565

6666
member _.TryReadCategoryLastVersion(category: TrancheId, ct): Task<int64 voption> = task {
6767
use! conn = connect ct
@@ -70,7 +70,7 @@ module Internal =
7070
use! reader = command.ExecuteReaderAsync(ct)
7171
return if reader.Read() then ValueSome (reader.GetInt64 0) else ValueNone }
7272

73-
let internal readBatch batchSize (store: MessageDbCategoryClient) struct (category, pos, ct): Task<Core.Batch<_>> =
73+
let internal readBatch batchSize (store: MessageDbCategoryClient) struct (category, pos, ct): Task<Batch<_>> =
7474
let positionInclusive = Position.toInt64 pos
7575
store.ReadCategoryMessages(category, positionInclusive, batchSize, ct)
7676

src/Propulsion.SqlStreamStore/SqlStreamStoreSource.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module private Impl =
1919
if streamFilter sn then Some struct (sn, msg) else None)
2020
let! items = if not withData then task { return filtered |> Seq.map (toStreamEvent null) |> Array.ofSeq }
2121
else filtered |> Seq.map readWithDataAsStreamEvent |> Propulsion.Internal.Task.sequential ct
22-
return ({ checkpoint = Propulsion.Feed.Position.parse page.NextPosition; items = items; isTail = page.IsEnd }: Propulsion.Feed.Core.Batch<_>) }
22+
return ({ checkpoint = Propulsion.Feed.Position.parse page.NextPosition; items = items; isTail = page.IsEnd }: Propulsion.Feed.Batch<_>) }
2323

2424
let readTailPositionForTranche (store: SqlStreamStore.IStreamStore) _trancheId ct = task {
2525
let! lastEventPos = store.ReadHeadPosition(ct)

src/Propulsion/Feed.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ type IFeedCheckpointStore =
3333
/// Determines the starting position, and checkpointing frequency for a given tranche
3434
abstract member Start: source: SourceId * tranche: TrancheId * establishOrigin: Func<CancellationToken, Task<Position>> option * ct: CancellationToken -> Task<Position>
3535
abstract member Commit: source: SourceId * tranche: TrancheId * pos: Position * CancellationToken -> Task
36+
37+
[<NoComparison; NoEquality>]
38+
type Batch<'F> =
39+
{ items: Propulsion.Streams.StreamEvent<'F>[]
40+
/// Next computed read position (inclusive). Checkpoint stores treat absence of a value as `Position.initial` (= `0`)
41+
checkpoint: Position
42+
/// Indicates whether the end of a feed has been reached (a batch being empty does not necessarily imply that)
43+
/// Implies tail sleep delay. May trigger completion of `Monitor.AwaitCompletion`
44+
isTail: bool }

src/Propulsion/FeedReader.fs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ open Propulsion.Feed
55
open Propulsion.Internal
66
open Serilog
77
open System
8-
open System.Collections.Generic
9-
10-
[<NoComparison; NoEquality>]
11-
type Batch<'F> =
12-
{ items: Propulsion.Streams.StreamEvent<'F>[]
13-
/// Next computed read position (inclusive). Checkpoint stores treat absence of a value as `Position.initial` (= `0`)
14-
checkpoint: Position
15-
/// Indicates whether the end of a feed has been reached (a batch being empty does not necessarily imply that)
16-
/// Implies tail sleep delay. May trigger completion of `Monitor.AwaitCompletion`
17-
isTail: bool }
188

199
module internal TimelineEvent =
2010

src/Propulsion/FeedSource.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ open Propulsion
55
open Propulsion.Feed
66
open Propulsion.Internal
77
open System
8-
open System.Collections.Generic
98

109
/// Drives reading and checkpointing for a set of feeds (tranches) of a custom source feed
1110
type FeedSourceBase internal
@@ -169,7 +168,7 @@ type FeedSource
169168
let readTs = Stopwatch.timestamp ()
170169
let! page = readPage.Invoke(trancheId, pos, ct)
171170
let items' = page.items |> Array.map (fun x -> struct (streamName, x))
172-
yield struct (Stopwatch.elapsed readTs, ({ items = items'; checkpoint = page.checkpoint; isTail = page.isTail }: Core.Batch<_>)) }
171+
yield struct (Stopwatch.elapsed readTs, ({ items = items'; checkpoint = page.checkpoint; isTail = page.isTail }: Batch<_>)) }
173172

174173
member internal _.Pump(readTranches: Func<CancellationToken, Task<TrancheId[]>>,
175174
readPage: Func<TrancheId, Position, CancellationToken, Task<Page<Propulsion.Sinks.EventBody>>>, ct): Task<unit> =

src/Propulsion/Internal.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ module Exception =
9090
let [<return: Struct>] (|Log|_|) log (e: exn) = log e; ValueNone
9191

9292
type CancellationToken = System.Threading.CancellationToken
93+
type IAsyncEnumerable<'T> = System.Collections.Generic.IAsyncEnumerable<'T>
9394
type Task = System.Threading.Tasks.Task
9495
type Task<'T> = System.Threading.Tasks.Task<'T>
9596
open System.Threading.Tasks
@@ -156,9 +157,7 @@ module Task =
156157
parallel_ 1 ct xs
157158
let parallelUnlimited ct xs: Task<'t []> =
158159
parallel_ 0 ct xs
159-
let inline ignore<'T> (a: Task<'T>): Task<unit> = task {
160-
let! _ = a
161-
return () }
160+
let inline ignore<'T> (a: Task<'T>): Task<unit> = task { let! _ = a in return () }
162161
let ofUnitTask (x: Task): Task<unit> = task { return! x }
163162
let periodically (f: CancellationToken -> Task<unit>) interval (ct: CancellationToken) = task {
164163
let t = new System.Threading.PeriodicTimer(interval) // no use as ct will Dispose

src/Propulsion/JsonSource.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type [<Sealed; AbstractClass>] JsonSource private () =
3737
let lineNo = int64 i + 1L
3838
try let items = if isEof then Array.empty
3939
else System.Text.Json.JsonDocument.Parse line |> parseFeedDoc |> Seq.toArray
40-
struct (System.TimeSpan.Zero, ({ items = items; isTail = isEof; checkpoint = Position.parse lineNo }: Core.Batch<_>))
40+
struct (System.TimeSpan.Zero, ({ items = items; isTail = isEof; checkpoint = Position.parse lineNo }: Batch<_>))
4141
with e -> raise <| exn($"File Parse error on L{lineNo}: '{line.Substring(0, 200)}'", e) }
4242
let source = SinglePassFeedSource(log, statsInterval, sourceId, crawl, checkpoints, sink, string)
4343
source.Start(fun _ct -> task { return [| TrancheId.parse "0" |] })

0 commit comments

Comments
 (0)