Skip to content

Commit

Permalink
add :subscribe_after option to InOrder subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis committed Jun 10, 2021
1 parent c87ce08 commit be69ee8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a
Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.4.0 - 2021-06-10

### Added

- Added `:subscribe_after` option which determines how long the producer will
wait before checking whether it should subscribe or not

## 0.3.0 - 2021-06-04

### Changed
Expand Down
10 changes: 9 additions & 1 deletion lib/kelvin/in_order_subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ defmodule Kelvin.InOrderSubscription do
`false` if the author intends on manually subscribing the producer. This
producer can be manually subscribed by `send/2`ing a message of
`:subscribe` to the process.
* `:subscribe_after` - (default: `Enum.random(3_000..5_000)`) the amount of
time to wait after initializing to query the `:subscribe_on_init?` option.
This can be useful to prevent all producers from trying to subscribe at
the same time and to await an active connection to the EventStoreDB.
* `:catch_up_chunk_size` - (default: `256`) the number of events to query
for each read chunk while catching up. This option presents a trade-off
between network queries and query duration over the network.
Expand All @@ -42,7 +46,11 @@ defmodule Kelvin.InOrderSubscription do
self: Keyword.get(opts, :name, self())
}

Process.send_after(self(), :check_auto_subscribe, Enum.random(3_000..5_000))
Process.send_after(
self(),
:check_auto_subscribe,
opts[:subscribe_after] || Enum.random(3_000..5_000)
)

{:producer, state}
end
Expand Down

0 comments on commit be69ee8

Please sign in to comment.