-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler.go
31 lines (26 loc) · 1.21 KB
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// SPDX-FileCopyrightText: © 2024 Kevin Conway <[email protected]>
// SPDX-License-Identifier: Apache-2.0
package cdc
import "context"
// ChangesHandler implementations are given batches of database changes. Each
// batch of changes is in the same order as the CDC log table. Batches may
// contain changes from multiple tables.
//
// If a handler returns an error then the entire batch is considered failed and
// retried. If a handler returns nil then the entire batch is considered
// successful and the relevant entries are removed from the CDC log table.
type ChangesHandler interface {
HandleChanges(ctx context.Context, changes Changes) error
}
// ChangesHandlerFunc is an adaptor to allow the use of ordinary functions as
// ChangesHandler implementations. Note that you should not use this type
// directly and should instead always target the ChangesHandler type. For
// example, the appropriate use of this adaptor is:
//
// var handler ChangesHandler = ChangesHandlerFunc(func(changes Changes) error {
// // handle changes
// })
type ChangesHandlerFunc func(ctx context.Context, changes Changes) error
func (fn ChangesHandlerFunc) HandleChanges(ctx context.Context, changes Changes) error {
return fn(ctx, changes)
}