Skip to content

Commit 06addb7

Browse files
authored
Add retry package (#6)
1 parent 24b29de commit 06addb7

File tree

4 files changed

+622
-3
lines changed

4 files changed

+622
-3
lines changed

hack/run_tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ run_dir="$(pwd)"
2525
packages="$(go list ./... | grep -v /validation/)"
2626
prefix="$(grep -oP 'module .*$' go.mod | sed 's|module ||')"
2727

28-
echo "Found packages: $packages in $run_dir with module $prefix"
28+
echo "Found packages: ${packages[@]} in $run_dir with module $prefix"
2929

30-
for p in "$packages"; do
30+
while IFS= read -r p; do
3131
pkg_dir="${p#$prefix}"
3232
if [ -z "$pkg_dir" ]; then
3333
echo "Package $p cannot have dir after trim $prefix"
@@ -37,4 +37,4 @@ for p in "$packages"; do
3737
echo "Run tests in $full_pkg_path"
3838
cd "$full_pkg_path"
3939
echo "test -v -p 1 $run_tests" | xargs go
40-
done
40+
done <<< "$packages"

pkg/retry/globals.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2025 Flant JSC
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+
// http://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 retry
16+
17+
import (
18+
"github.com/name212/govalue"
19+
20+
"github.com/deckhouse/lib-dhctl/pkg/log"
21+
)
22+
23+
type GlobalInterruptChecker func() bool
24+
25+
func SetGlobalInterruptChecker(checker GlobalInterruptChecker) {
26+
if govalue.IsNil(checker) {
27+
return
28+
}
29+
30+
globalInterruptChecker = checker
31+
}
32+
33+
// SetGlobalDefaultLogger
34+
// Deprecated:
35+
// global logger used for backward compatibility in dhctl with
36+
// deprecated functions NewLoop and NewSilentLoop
37+
// Please use NewLoopWithParams and NewSilentLoopWithParams
38+
func SetGlobalDefaultLogger(logger log.Logger) {
39+
if govalue.IsNil(logger) {
40+
return
41+
}
42+
43+
defaultLogger = logger
44+
}
45+
46+
var (
47+
globalInterruptChecker GlobalInterruptChecker = func() bool { return false }
48+
defaultLogger log.Logger = log.NewDummyLogger(false)
49+
silentLogger = log.NewSilentLogger()
50+
)
51+
52+
func getDefaultSilentLogger() *log.SilentLogger {
53+
switch defaultLogger.(type) {
54+
case *log.TeeLogger:
55+
return defaultLogger.SilentLogger()
56+
default:
57+
return silentLogger
58+
}
59+
}

0 commit comments

Comments
 (0)