Skip to content
This repository was archived by the owner on Mar 15, 2024. It is now read-only.

Commit 00e2cf2

Browse files
authored
Prepare release 0.12.0 #23
- Fix GolangCI notices - typos - scope lint - if-else-if -> switch-case - remove binding to all interfaces - missing error checks - missing params checks - Update web-module to new mserv - missing error check in tests - `mserv.NewHTTPServer` was changed - Refactoring workers-module - test coverage - update to new version of `chapsuk/worker` - remove logger from params (not need anymore) - remove redis from dependencies (used worker.Locker interface instead) - Dependencies: - Update: - github.com/chapsuk/mserv v1.1.0 - github.com/chapsuk/worker v1.0.0 - github.com/davecgh/go-spew v1.1.1 - github.com/prometheus/client_golang v1.1.0 - github.com/spf13/viper v1.4.0 - github.com/stretchr/testify v1.4.0 - go.uber.org/atomic v1.4.0 - go.uber.org/zap v1.10.0 - Removed: - github.com/bsm/redis-lock - github.com/golang/protobuf - github.com/go-redis/redis - github.com/chapsuk/wait - github.com/onsi/ginkgo - github.com/onsi/gomega - github.com/prometheus/common - github.com/robfig/cron - github.com/smartystreets/goconvey - go.uber.org/multierr - google.golang.org/grpc
2 parents 1dd1100 + 1028e38 commit 00e2cf2

File tree

13 files changed

+485
-154
lines changed

13 files changed

+485
-154
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
go: [ '1.11.x', '1.12.x' ]
10+
go: [ '1.11.x', '1.12.x', '1.13.x']
1111
steps:
1212

1313
- name: Setup go
@@ -38,6 +38,6 @@ jobs:
3838

3939
- name: Tests
4040
run: go test -coverprofile=coverage.txt -covermode=atomic ./...
41-
41+
4242
- name: Codecov
4343
run: bash <(curl -s https://codecov.io/bash)

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: go
22
go:
33
- 1.11.x
44
- 1.12.x
5+
- 1.13.x
56
env:
67
- GO111MODULE=on
78
install:
@@ -14,4 +15,4 @@ after_success:
1415
- bash <(curl -s https://codecov.io/bash)
1516
matrix:
1617
allow_failures:
17-
- go: tip
18+
- go: tip

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,6 @@ workers:
343343
## ticker: 30s # run job every 30s
344344
## timer: 30s # run job every 30s and reset timer
345345
## cron: * * * * * # run job by crontab specs, e.g. "* * * * *"
346-
## lock: # use lock by redis
347-
## key: myKey
348-
## ttl: 150s
349-
## retry: # retry get lock to run job
350-
## count: 5
351-
## timeout: 30s
352346
```
353347

354348
**Features**

go.mod

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
module github.com/im-kulikov/helium
22

3+
go 1.11
4+
35
require (
46
bou.ke/monkey v1.0.1
5-
github.com/bsm/redis-lock v8.0.0+incompatible // indirect
6-
github.com/chapsuk/mserv v0.4.1
7-
github.com/chapsuk/wait v0.3.1 // indirect
8-
github.com/chapsuk/worker v0.4.0
9-
github.com/go-redis/redis v6.15.2+incompatible
10-
github.com/golang/protobuf v1.3.1 // indirect
11-
github.com/onsi/ginkgo v1.8.0 // indirect
12-
github.com/onsi/gomega v1.5.0 // indirect
7+
github.com/chapsuk/mserv v1.1.0
8+
github.com/chapsuk/worker v1.0.0
9+
github.com/davecgh/go-spew v1.1.1
1310
github.com/pkg/errors v0.8.1
14-
github.com/prometheus/client_golang v0.9.2
15-
github.com/prometheus/common v0.3.0 // indirect
16-
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967 // indirect
17-
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
18-
github.com/spf13/viper v1.3.2
19-
github.com/stretchr/testify v1.3.0
20-
go.uber.org/atomic v1.3.2
11+
github.com/prometheus/client_golang v1.1.0
12+
github.com/spf13/viper v1.4.0
13+
github.com/stretchr/testify v1.4.0
14+
go.uber.org/atomic v1.4.0
2115
go.uber.org/dig v1.7.0
22-
go.uber.org/multierr v1.1.0 // indirect
23-
go.uber.org/zap v1.9.1
24-
google.golang.org/grpc v1.20.1 // indirect
16+
go.uber.org/zap v1.10.0
2517
)
2618

2719
// Blocked in Russia

go.sum

Lines changed: 105 additions & 52 deletions
Large diffs are not rendered by default.

grace/grace_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ func TestGrace(t *testing.T) {
1919
// waiting to run the goroutine and channel of signals
2020
<-time.Tick(100 * time.Millisecond)
2121

22-
for _, sig := range []syscall.Signal{syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP} {
22+
signals := []syscall.Signal{syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP}
23+
for i := range signals {
24+
sig := signals[i]
2325
t.Run(fmt.Sprintf("should cancel context on %s signal", sig), func(t *testing.T) {
2426
is := assert.New(t)
2527

helium.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ func CatchTrace(err error) {
133133
fn reflect.Value
134134
)
135135

136-
if v.Type().Kind() != reflect.Struct {
136+
switch {
137+
case v.Type().Kind() != reflect.Struct,
138+
!v.FieldByName("Reason").IsValid():
137139
break
138-
} else if !v.FieldByName("Reason").IsValid() {
139-
break
140-
} else if v.FieldByName("Func").IsValid() {
140+
case v.FieldByName("Func").IsValid():
141141
fn = v.FieldByName("Func")
142142
}
143143

web/servers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ var (
6666

6767
// NewMultiServer returns new multi servers group
6868
func NewMultiServer(params MultiServerParams) mserv.Server {
69-
mserv.SetLogger(params.Logger)
7069
return mserv.New(params.Servers...)
7170
}
7271

@@ -99,21 +98,21 @@ func NewAPIServer(v *viper.Viper, l logger.StdLogger, h http.Handler) ServerResu
9998

10099
// NewHTTPServer creates http-server that will be embedded into multi-server
101100
func NewHTTPServer(v *viper.Viper, key string, h http.Handler, l logger.StdLogger) ServerResult {
102-
if h == nil {
101+
switch {
102+
case h == nil:
103103
l.Printf("Empty handler for %s server, skip", key)
104104
return ServerResult{}
105-
} else if v.GetBool(key + ".disabled") {
105+
case v.GetBool(key + ".disabled"):
106106
l.Printf("Server %s disabled", key)
107107
return ServerResult{}
108-
} else if !v.IsSet(key + ".address") {
108+
case !v.IsSet(key + ".address"):
109109
l.Printf("Empty bind address for %s server, skip", key)
110110
return ServerResult{}
111111
}
112112

113113
l.Printf("Create %s http server, bind address: %s", key, v.GetString(key+".address"))
114114
return ServerResult{
115115
Server: mserv.NewHTTPServer(
116-
v.GetDuration(key+".shutdown_timeout"),
117116
&http.Server{
118117
Addr: v.GetString(key + ".address"),
119118
Handler: h,
@@ -123,5 +122,6 @@ func NewHTTPServer(v *viper.Viper, key string, h http.Handler, l logger.StdLogge
123122
IdleTimeout: v.GetDuration(key + ".idle_timeout"),
124123
MaxHeaderBytes: v.GetInt(key + ".max_header_bytes"),
125124
},
125+
mserv.HTTPShutdownTimeout(v.GetDuration(key+".shutdown_timeout")),
126126
)}
127127
}

web/servers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func TestServers(t *testing.T) {
128128

129129
// Randomize ports:
130130
for name := range servers {
131-
servers[name], err = net.Listen("tcp", ":0")
131+
servers[name], err = net.Listen("tcp", "127.0.0.1:0")
132132
assert.NoError(err)
133133
assert.NoError(servers[name].Close())
134134

@@ -158,7 +158,7 @@ func TestServers(t *testing.T) {
158158
err = di.Invoke(func(serve mserv.Server) {
159159
assert.IsType(&mserv.MultiServer{}, serve)
160160

161-
serve.Start()
161+
assert.NoError(serve.Start())
162162
})
163163
assert.NoError(err)
164164

workers/errors.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@ const (
77
// ErrMissingKey when config key for worker is missing
88
ErrMissingKey = Error("missing worker key")
99

10-
// ErrRedisClientNil when redis client not provided
11-
ErrRedisClientNil = Error("gotten nil redis client for exclusive worker")
10+
// ErrEmptyConfig when viper not passed to params
11+
ErrEmptyConfig = Error("empty config")
12+
13+
// ErrEmptyWorkers when workers not passed to params
14+
ErrEmptyWorkers = Error("empty workers")
15+
16+
// ErrEmptyLocker when locker required,
17+
// but not passed to params
18+
ErrEmptyLocker = Error("empty locker")
19+
20+
// ErrEmptyJob when worker job is nil
21+
ErrEmptyJob = Error("empty job")
1222
)
1323

1424
// Error converts constant error from string

workers/errors_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package workers
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestError_Error(t *testing.T) {
8+
tests := []struct {
9+
name string
10+
e Error
11+
want string
12+
}{
13+
{name: "empty error"},
14+
{name: "custom error", e: Error("custom"), want: "custom"},
15+
}
16+
for i := range tests {
17+
tt := tests[i]
18+
t.Run(tt.name, func(t *testing.T) {
19+
if got := tt.e.Error(); got != tt.want {
20+
t.Errorf("Error() = %v, want %v", got, tt.want)
21+
}
22+
})
23+
}
24+
}

0 commit comments

Comments
 (0)