Skip to content

Commit de2903e

Browse files
Merge pull request #25 from rabbitmq/gen-batch-server-24
Upgrade to match modern `gen_server` (continuation of #24)
2 parents a10bd06 + 6dd7057 commit de2903e

6 files changed

Lines changed: 311 additions & 81 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
otp: ['26', '27', '28']
14+
steps:
15+
- uses: actions/checkout@v6
16+
- uses: erlef/setup-beam@v1
17+
with:
18+
otp-version: ${{ matrix.otp }}
19+
rebar3-version: '3.24'
20+
- uses: actions/cache@v4
21+
with:
22+
path: |
23+
_build
24+
~/.cache/rebar3
25+
key: ${{ runner.os }}-otp-${{ matrix.otp }}-rebar3-${{ hashFiles('rebar.lock') }}
26+
restore-keys: |
27+
${{ runner.os }}-otp-${{ matrix.otp }}-rebar3-
28+
- run: epmd -daemon
29+
- run: rebar3 ct --sname batch_test
30+
- run: rebar3 dialyzer
31+
- run: rebar3 xref

README.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,27 @@ The timeout is optional and defaults to 5000ms.
8989

9090
Types:
9191
Args = term()
92-
Result = {ok, State} | {stop, Reason}
93-
State = term(),
92+
Result = {ok, State} |
93+
{ok, State, {continue, Continue}} |
94+
ignore |
95+
{stop, Reason}
96+
State = term()
97+
Continue = term()
9498
Reason = term()
9599

96-
97100
Called whenever a `gen_batch_server` is started with the arguments provided
98101
to `start_link/4`.
99102

103+
Returning `{ok, State, {continue, Continue}}` will cause `handle_continue/2`
104+
to be called before processing any messages.
105+
106+
Returning `ignore` will cause `start_link` to return `ignore` and the process
107+
will exit normally without a crash report.
108+
109+
Can be used in scenarios where a `gen_batch_server`
110+
depends on a resource that can be temporarily
111+
unavailable (e.g. when a Ra member runs out of disk space).
112+
100113
#### Module:handle_batch(Batch, State) -> Result.
101114

102115
Types:
@@ -105,7 +118,11 @@ to `start_link/4`.
105118
Op = {cast, UserOp} |
106119
{call, from(), UserOp} |
107120
{info, UserOp}.
108-
Result = {ok, State} | {ok, Actions, State} | {stop, Reason}
121+
Result = {ok, State} |
122+
{ok, State, {continue, Continue}} |
123+
{ok, Actions, State} |
124+
{ok, Actions, State, {continue, Continue}} |
125+
{stop, Reason}
109126
State = term()
110127
From = {Pid :: pid(), Tag :: reference()}
111128
Action = {reply, From, Msg} | garbage_collect
@@ -115,6 +132,24 @@ to `start_link/4`.
115132
Called whenever a new batch is ready for processing. The implementation can
116133
optionally return a list of reply actions used to reply to `call` operations.
117134

135+
#### Module:handle_continue(Continue, State) -> Result
136+
137+
Types:
138+
Continue = term()
139+
State = term()
140+
Result = {ok, NewState} |
141+
{ok, NewState, {continue, NewContinue}} |
142+
{stop, Reason}
143+
NewState = term()
144+
NewContinue = term()
145+
Reason = term()
146+
147+
Optional. Called after `init/1` returns `{ok, State, {continue, Continue}}` or
148+
after `handle_batch/2` returns with a `{continue, Continue}` tuple.
149+
150+
Most useful for post-`init/2` work that needs
151+
the server to be registered first.
152+
118153
#### Module:terminate(Reason, State) -> Result
119154

120155
Types:
@@ -138,4 +173,3 @@ Optional. Used to provide a custom formatting of the user state.
138173
# Copyright
139174

140175
(c) 2018-2023 Broadcom. All Rights Reserved. The term Broadcom refers to Broadcom Inc. and/or its subsidiaries.
141-

rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{minimum_otp_vsn, "22.3"}.
1+
{minimum_otp_vsn, "26"}.
22
{deps, []}.
33
{project_plugins, [rebar3_hex]}.
44
{profiles,

src/gen_batch_server.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{licenses,["Apache-2.0","MPL-2.0"]},
44
{links,[{"github",
55
"https://github.com/rabbitmq/gen-batch-server"}]},
6-
{vsn,"0.8.9"},
6+
{vsn,"0.9.0"},
77
{modules,[gen_batch_server]},
88
{registered,[]},
99
{applications,[kernel,stdlib]},

0 commit comments

Comments
 (0)