github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/config/config.go (about) 1 package config 2 3 import ( 4 "time" 5 6 "github.com/ydb-platform/ydb-go-sdk/v3/trace" 7 ) 8 9 type Common struct { 10 operationTimeout time.Duration 11 operationCancelAfter time.Duration 12 disableAutoRetry bool 13 traceRetry trace.Retry 14 15 panicCallback func(e interface{}) 16 } 17 18 // AutoRetry defines auto-retry flag 19 func (c *Common) AutoRetry() bool { 20 return !c.disableAutoRetry 21 } 22 23 // PanicCallback returns user-defined panic callback 24 // If nil - panic callback not defined 25 func (c *Common) PanicCallback() func(e interface{}) { 26 return c.panicCallback 27 } 28 29 // OperationTimeout is the maximum amount of time a YDB server will process 30 // an operation. After timeout exceeds YDB will try to cancel operation and 31 // regardless of the cancellation appropriate error will be returned to 32 // the client. 33 // If OperationTimeout is zero then no timeout is used. 34 func (c *Common) OperationTimeout() time.Duration { 35 return c.operationTimeout 36 } 37 38 // OperationCancelAfter is the maximum amount of time a YDB server will process an 39 // operation. After timeout exceeds YDB will try to cancel operation and if 40 // it succeeds appropriate error will be returned to the client; otherwise 41 // processing will be continued. 42 // If OperationCancelAfter is zero then no timeout is used. 43 func (c *Common) OperationCancelAfter() time.Duration { 44 return c.operationCancelAfter 45 } 46 47 func (c *Common) TraceRetry() *trace.Retry { 48 return &c.traceRetry 49 } 50 51 // SetOperationTimeout define the maximum amount of time a YDB server will process 52 // an operation. After timeout exceeds YDB will try to cancel operation and 53 // regardless of the cancellation appropriate error will be returned to 54 // the client. 55 // 56 // If OperationTimeout is zero then no timeout is used. 57 func SetOperationTimeout(c *Common, operationTimeout time.Duration) { 58 c.operationTimeout = operationTimeout 59 } 60 61 // SetOperationCancelAfter set the maximum amount of time a YDB server will process an 62 // operation. After timeout exceeds YDB will try to cancel operation and if 63 // it succeeds appropriate error will be returned to the client; otherwise 64 // processing will be continued. 65 // 66 // If OperationCancelAfter is zero then no timeout is used. 67 func SetOperationCancelAfter(c *Common, operationCancelAfter time.Duration) { 68 c.operationCancelAfter = operationCancelAfter 69 } 70 71 // SetPanicCallback applies panic callback to config 72 func SetPanicCallback(c *Common, panicCallback func(e interface{})) { 73 c.panicCallback = panicCallback 74 } 75 76 // SetAutoRetry affects on AutoRetry() flag 77 func SetAutoRetry(c *Common, autoRetry bool) { 78 c.disableAutoRetry = !autoRetry 79 } 80 81 func SetTraceRetry(c *Common, t *trace.Retry, opts ...trace.RetryComposeOption) { 82 c.traceRetry = *c.traceRetry.Compose(t, opts...) 83 }