github.com/ydb-platform/ydb-go-sdk/v3@v3.89.2/coordination/options/options.go (about) 1 package options 2 3 import ( 4 "math" 5 "time" 6 7 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Coordination" 8 ) 9 10 // WithDescription returns an SessionOption that specifies a user-defined description that may be used to describe 11 // the client. 12 func WithDescription(description string) SessionOption { 13 return func(c *CreateSessionOptions) { 14 c.Description = description 15 } 16 } 17 18 // WithSessionTimeout returns an SessionOption that specifies the timeout during which client may restore a 19 // detached session. The client is forced to terminate the session if the last successful session request occurred 20 // earlier than this time. 21 // 22 // If this is not set, the client uses the default 5 seconds. 23 func WithSessionTimeout(timeout time.Duration) SessionOption { 24 return func(c *CreateSessionOptions) { 25 c.SessionTimeout = timeout 26 } 27 } 28 29 // WithSessionStartTimeout returns an SessionOption that specifies the time that the client should wait for a 30 // response to the StartSession request from the server before it terminates the gRPC stream and tries to reconnect. 31 // 32 // If this is not set, the client uses the default time 1 second. 33 func WithSessionStartTimeout(timeout time.Duration) SessionOption { 34 return func(c *CreateSessionOptions) { 35 c.SessionStartTimeout = timeout 36 } 37 } 38 39 // WithSessionStopTimeout returns an SessionOption that specifies the time that the client should wait for a 40 // response to the StopSession request from the server before it terminates the gRPC stream and tries to reconnect. 41 // 42 // If this is not set, the client uses the default time 1 second. 43 func WithSessionStopTimeout(timeout time.Duration) SessionOption { 44 return func(c *CreateSessionOptions) { 45 c.SessionStartTimeout = timeout 46 } 47 } 48 49 // WithSessionKeepAliveTimeout returns an SessionOption that specifies the time that the client will wait before 50 // it terminates the gRPC stream and tries to reconnect if no successful responses have been received from the server. 51 // 52 // If this is not set, the client uses the default time 10 seconds. 53 func WithSessionKeepAliveTimeout(timeout time.Duration) SessionOption { 54 return func(c *CreateSessionOptions) { 55 c.SessionKeepAliveTimeout = timeout 56 } 57 } 58 59 // WithSessionReconnectDelay returns an SessionOption that specifies the time that the client will wait before it 60 // tries to reconnect the underlying gRPC stream in case of error. 61 // 62 // If this is not set, the client uses the default time 500 milliseconds. 63 func WithSessionReconnectDelay(delay time.Duration) SessionOption { 64 return func(c *CreateSessionOptions) { 65 c.SessionReconnectDelay = delay 66 } 67 } 68 69 // SessionOption configures how we create a new session. 70 type SessionOption func(c *CreateSessionOptions) 71 72 // CreateSessionOptions configure an Session call. CreateSessionOptions are set by the SessionOption values 73 // passed to the Session function. 74 type CreateSessionOptions struct { 75 Description string 76 SessionTimeout time.Duration 77 SessionStartTimeout time.Duration 78 SessionStopTimeout time.Duration 79 SessionKeepAliveTimeout time.Duration 80 SessionReconnectDelay time.Duration 81 } 82 83 // WithEphemeral returns an AcquireSemaphoreOption that causes to create an ephemeral semaphore. 84 // 85 // Ephemeral semaphores are created with the first acquire operation and automatically deleted with the last release 86 // operation. Ephemeral semaphore are always created with the limit of coordination.MaxSemaphoreLimit. 87 func WithEphemeral(ephemeral bool) AcquireSemaphoreOption { 88 return func(c *Ydb_Coordination.SessionRequest_AcquireSemaphore) { 89 c.Ephemeral = ephemeral 90 } 91 } 92 93 // WithAcquireTimeout returns an AcquireSemaphoreOption which sets the timeout after which the operation fails if it 94 // is still waiting in the queue. Use 0 to make the AcquireSemaphore method fail immediately if the semaphore is already 95 // acquired by another session. 96 // 97 // If this is not set, the client waits for the acquire operation result until the operation or session context is done. 98 // You can reset the default value of this timeout by calling the WithAcquireInfiniteTimeout method. 99 func WithAcquireTimeout(timeout time.Duration) AcquireSemaphoreOption { 100 return func(c *Ydb_Coordination.SessionRequest_AcquireSemaphore) { 101 c.TimeoutMillis = uint64(timeout.Milliseconds()) 102 } 103 } 104 105 // WithAcquireInfiniteTimeout returns an AcquireSemaphoreOption which disables the timeout after which the operation 106 // fails if it is still waiting in the queue. 107 // 108 // This is the default behavior. You can set the specific timeout by calling the WithAcquireTimeout method. 109 func WithAcquireInfiniteTimeout() AcquireSemaphoreOption { 110 return func(c *Ydb_Coordination.SessionRequest_AcquireSemaphore) { 111 c.TimeoutMillis = math.MaxUint64 112 } 113 } 114 115 // WithAcquireData returns an AcquireSemaphoreOption which attaches user-defined data to the operation. 116 func WithAcquireData(data []byte) AcquireSemaphoreOption { 117 return func(c *Ydb_Coordination.SessionRequest_AcquireSemaphore) { 118 c.Data = data 119 } 120 } 121 122 // AcquireSemaphoreOption configures how we acquire a semaphore. 123 type AcquireSemaphoreOption func(c *Ydb_Coordination.SessionRequest_AcquireSemaphore) 124 125 // WithForceDelete return a DeleteSemaphoreOption which allows to delete a semaphore even if it is currently acquired 126 // by other sessions. 127 func WithForceDelete(force bool) DeleteSemaphoreOption { 128 return func(c *Ydb_Coordination.SessionRequest_DeleteSemaphore) { 129 c.Force = force 130 } 131 } 132 133 // DeleteSemaphoreOption configures how we delete a semaphore. 134 type DeleteSemaphoreOption func(c *Ydb_Coordination.SessionRequest_DeleteSemaphore) 135 136 // WithCreateData return a CreateSemaphoreOption which attaches user-defined data to the semaphore. 137 func WithCreateData(data []byte) CreateSemaphoreOption { 138 return func(c *Ydb_Coordination.SessionRequest_CreateSemaphore) { 139 c.Data = data 140 } 141 } 142 143 // CreateSemaphoreOption configures how we create a semaphore. 144 type CreateSemaphoreOption func(c *Ydb_Coordination.SessionRequest_CreateSemaphore) 145 146 // WithUpdateData return a UpdateSemaphoreOption which changes user-defined data in the semaphore. 147 func WithUpdateData(data []byte) UpdateSemaphoreOption { 148 return func(c *Ydb_Coordination.SessionRequest_UpdateSemaphore) { 149 c.Data = data 150 } 151 } 152 153 // UpdateSemaphoreOption configures how we update a semaphore. 154 type UpdateSemaphoreOption func(c *Ydb_Coordination.SessionRequest_UpdateSemaphore) 155 156 // WithDescribeOwners return a DescribeSemaphoreOption which causes server send the list of owners in the response 157 // to the DescribeSemaphore request. 158 func WithDescribeOwners(describeOwners bool) DescribeSemaphoreOption { 159 return func(c *Ydb_Coordination.SessionRequest_DescribeSemaphore) { 160 c.IncludeOwners = describeOwners 161 } 162 } 163 164 // WithDescribeWaiters return a DescribeSemaphoreOption which causes server send the list of waiters in the response 165 // to the DescribeSemaphore request. 166 func WithDescribeWaiters(describeWaiters bool) DescribeSemaphoreOption { 167 return func(c *Ydb_Coordination.SessionRequest_DescribeSemaphore) { 168 c.IncludeWaiters = describeWaiters 169 } 170 } 171 172 // DescribeSemaphoreOption configures how we update a semaphore. 173 type DescribeSemaphoreOption func(c *Ydb_Coordination.SessionRequest_DescribeSemaphore)