You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2018/11/02 20:42:09 UTC
[GitHub] jrushford commented on a change in pull request #2970: Add an
exponential time backoff object for use in traffic_monitor.
jrushford commented on a change in pull request #2970: Add an exponential time backoff object for use in traffic_monitor.
URL: https://github.com/apache/trafficcontrol/pull/2970#discussion_r230502500
##########
File path: lib/go-tc/backoff.go
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package tc
+
+/*
+ * Used to return an exponentially increasing time.Duration value that may be used
+ * to sleep between retries.
+ */
+
+import (
+ "github.com/apache/trafficcontrol/lib/go-log"
+ "math"
+ "math/rand"
+ "time"
+)
+
+// default minimum milliseconds is 30 msec
+const DefaultMinMs = time.Duration(100) * time.Millisecond
+
+// default maximum millseconds is 60000 (1m 0s)
+const DefaultMaxMs = time.Duration(60000) * time.Millisecond
+
+const DefaultFactor = float64(2)
+
+type BackOff struct {
+ attempt float64
+ Factor float64
+ Min time.Duration
+ Max time.Duration
+}
+
+func NewBackOff(minMs time.Duration, maxMs time.Duration, factor float64) *BackOff {
+ min := minMs
+ max := maxMs
+ fac := factor
+
+ // verify arguments and set defaults if necessary.
+ if fac <= 1 {
+ log.Errorf("'The setting for 'Backoff.Factor' is too low, '%v', using default, '%v'\n", fac, DefaultFactor)
+ fac = DefaultFactor
+ }
+ if min < DefaultMinMs {
+ log.Errorf("'The setting for 'Backoff.Min' is too low, '%v', using default, '%v'\n", min, DefaultMinMs)
+ min = DefaultMinMs
+ }
+ if max <= DefaultMinMs {
Review comment:
you're right, it should. I'll fix it.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services