forked from ydb-platform/ent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretry_debug.go
More file actions
47 lines (41 loc) · 1.14 KB
/
retry_debug.go
File metadata and controls
47 lines (41 loc) · 1.14 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2019-present Facebook Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
package sql
import (
"context"
"entgo.io/ent/dialect"
)
// debugRetryExecutor wraps a RetryExecutor to preserve debug logging.
type debugRetryExecutor struct {
RetryExecutor
log func(context.Context, ...any)
}
// Do executes the operation with debug logging preserved.
func (d *debugRetryExecutor) Do(
ctx context.Context,
fn func(ctx context.Context, drv dialect.Driver) error,
opts ...any,
) error {
return d.RetryExecutor.Do(
ctx,
func(ctx context.Context, drv dialect.Driver) error {
return fn(ctx, dialect.DebugWithContext(drv, d.log))
},
opts...,
)
}
// DoTx executes the operation within a transaction with debug logging preserved.
func (d *debugRetryExecutor) DoTx(
ctx context.Context,
fn func(ctx context.Context, drv dialect.Driver) error,
opts ...any,
) error {
return d.RetryExecutor.DoTx(
ctx,
func(ctx context.Context, drv dialect.Driver) error {
return fn(ctx, dialect.DebugWithContext(drv, d.log))
},
opts...,
)
}