github.com/google/fleetspeak@v0.1.15-0.20240426164851-4f31f62c1aea/fleetspeak/src/server/internal/ftime/retry.go (about) 1 // Copyright 2017 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package ftime 16 17 import ( 18 "math" 19 "math/rand" 20 "time" 21 ) 22 23 // ClientRetryTime determines how long to wait for an acknowledgement before 24 // sending a message to a client again. The normal implementation waits 15 25 // minutes. It is mutable primarily to support testing. 26 var ClientRetryTime = func() time.Time { 27 return Now().Add(15 * time.Minute) 28 } 29 30 // ServerRetryTime determines how long to wait before attempting to process a 31 // message again on the FS server. The normal implementation provides 32 // exponential backoff with jitter, with an initial wait of 1-2 min. It is 33 // mutable primarily to support testing. 34 var ServerRetryTime = func(retryCount uint32) time.Time { 35 delay := float64(time.Minute) * math.Pow(1.1, float64(retryCount)) 36 delay *= 1.0 + rand.Float64() 37 38 return Now().Add(time.Duration(delay)) 39 }