Skip to content

Commit 7b2d632

Browse files
committed
document the :deadline option for append_batch/5
With the change in EventStoreDB 21.10.5, you can pass the deadline for BatchAppend as a duration instead of a timestamp which is much more sane. This change allows passing the new duration type as {:duration, seconds, nanos} and adds the missing documentation for the key.
1 parent 468037b commit 7b2d632

4 files changed

Lines changed: 48 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ behind new EventStoreDB versions. You should not downgrade your Spear version
1111
in order to avoid these features: Spear aims to keep a stable interface usable
1212
across all EventStoreDB versions v20+.
1313

14+
## 1.1.0 - 2022-07-08
15+
16+
### Added
17+
18+
- A duration may now be specified for the `:deadline` option to
19+
`Spear.append_batch/5`
20+
- Passing a duration (instead of a timestamp) requires EventStoreDB
21+
version 21.10.5 or higher
22+
1423
## 1.0.2 - 2022-06-02
1524

1625
### Fixed

lib/spear.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ defmodule Spear do
483483
use as credentials for the request. This option overrides any credentials
484484
set in the connection configuration, if present. See the
485485
[Security guide](guides/security.md) for more details.
486+
* `:deadline` - (default: `nil`) the deadline for the batch to be appended.
487+
This is like `:timeout` but is interpreted on the EventStoreDB server.
488+
This may be a `DateTime` or a tuple of `{seconds, nanos}` since 1970
489+
(smeared) but may be a tuple `{:duration, seconds, nanos}` when using
490+
EventStoreDB version 21.10.5 or higher.
486491
* `:timeout` - (default: `5_000`) the timeout for the initial call to
487492
open the batch request.
488493

lib/spear/records/google.ex

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ defmodule Spear.Records.Google do
99
end
1010
end
1111

12+
# message Timestamp {
13+
# // Represents seconds of UTC time since Unix epoch
14+
# // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
15+
# // 9999-12-31T23:59:59Z inclusive.
16+
# int64 seconds = 1;
17+
#
18+
# // Non-negative fractions of a second at nanosecond resolution. Negative
19+
# // second values with fractions must still have non-negative nanos values
20+
# // that count forward in time. Must be from 0 to 999,999,999
21+
# // inclusive.
22+
# int32 nanos = 2;
23+
# }
1224
if Version.match?(System.version(), ">= 1.11.0") do
1325
def timestamp(%DateTime{} = datetime) do
1426
# google timestamp is number of seconds from the first second of 1970 (smeared)
@@ -21,4 +33,22 @@ defmodule Spear.Records.Google do
2133
def timestamp({seconds, nanos}) do
2234
{:"google.protobuf.Timestamp", seconds, nanos}
2335
end
36+
37+
# message Duration {
38+
# // Signed seconds of the span of time. Must be from -315,576,000,000
39+
# // to +315,576,000,000 inclusive. Note: these bounds are computed from:
40+
# // 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
41+
# int64 seconds = 1;
42+
#
43+
# // Signed fractions of a second at nanosecond resolution of the span
44+
# // of time. Durations less than one second are represented with a 0
45+
# // `seconds` field and a positive or negative `nanos` field. For durations
46+
# // of one second or more, a non-zero value for the `nanos` field must be
47+
# // of the same sign as the `seconds` field. Must be from -999,999,999
48+
# // to +999,999,999 inclusive.
49+
# int32 nanos = 2;
50+
# }
51+
def duration(seconds, nanos) do
52+
{:"google.protobuf.Duration", seconds, nanos}
53+
end
2454
end

lib/spear/writing.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ defmodule Spear.Writing do
132132

133133
defp map_deadline(nil), do: :undefined
134134
# coveralls-ignore-start
135-
defp map_deadline(deadline), do: {:deadline_21_10_0, Google.timestamp(deadline)}
135+
defp map_deadline({:duration, seconds, nanos}),
136+
do: {:deadline, Google.duration(seconds, nanos)}
137+
138+
defp map_deadline(timestamp), do: {:deadline_21_10_0, Google.timestamp(timestamp)}
136139
# coveralls-ignore-stop
137140

138141
defp map_expected_position(revision) when is_integer(revision) and revision >= 0,

0 commit comments

Comments
 (0)