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

Commit

Permalink
Prepare release 0.12.0 #23
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
im-kulikov authored Sep 18, 2019
2 parents 1dd1100 + 1028e38 commit 00e2cf2
Show file tree
Hide file tree
Showing 13 changed files with 485 additions and 154 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.11.x', '1.12.x' ]
go: [ '1.11.x', '1.12.x', '1.13.x']
steps:

- name: Setup go
Expand Down Expand Up @@ -38,6 +38,6 @@ jobs:

- name: Tests
run: go test -coverprofile=coverage.txt -covermode=atomic ./...

- name: Codecov
run: bash <(curl -s https://codecov.io/bash)
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: go
go:
- 1.11.x
- 1.12.x
- 1.13.x
env:
- GO111MODULE=on
install:
Expand All @@ -14,4 +15,4 @@ after_success:
- bash <(curl -s https://codecov.io/bash)
matrix:
allow_failures:
- go: tip
- go: tip
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,6 @@ workers:
## ticker: 30s # run job every 30s
## timer: 30s # run job every 30s and reset timer
## cron: * * * * * # run job by crontab specs, e.g. "* * * * *"
## lock: # use lock by redis
## key: myKey
## ttl: 150s
## retry: # retry get lock to run job
## count: 5
## timeout: 30s
```

**Features**
Expand Down
28 changes: 10 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
module github.com/im-kulikov/helium

go 1.11

require (
bou.ke/monkey v1.0.1
github.com/bsm/redis-lock v8.0.0+incompatible // indirect
github.com/chapsuk/mserv v0.4.1
github.com/chapsuk/wait v0.3.1 // indirect
github.com/chapsuk/worker v0.4.0
github.com/go-redis/redis v6.15.2+incompatible
github.com/golang/protobuf v1.3.1 // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/chapsuk/mserv v1.1.0
github.com/chapsuk/worker v1.0.0
github.com/davecgh/go-spew v1.1.1
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v0.9.2
github.com/prometheus/common v0.3.0 // indirect
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967 // indirect
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
github.com/spf13/viper v1.3.2
github.com/stretchr/testify v1.3.0
go.uber.org/atomic v1.3.2
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/dig v1.7.0
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.9.1
google.golang.org/grpc v1.20.1 // indirect
go.uber.org/zap v1.10.0
)

// Blocked in Russia
Expand Down
157 changes: 105 additions & 52 deletions go.sum

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion grace/grace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ func TestGrace(t *testing.T) {
// waiting to run the goroutine and channel of signals
<-time.Tick(100 * time.Millisecond)

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

Expand Down
8 changes: 4 additions & 4 deletions helium.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ func CatchTrace(err error) {
fn reflect.Value
)

if v.Type().Kind() != reflect.Struct {
switch {
case v.Type().Kind() != reflect.Struct,
!v.FieldByName("Reason").IsValid():
break
} else if !v.FieldByName("Reason").IsValid() {
break
} else if v.FieldByName("Func").IsValid() {
case v.FieldByName("Func").IsValid():
fn = v.FieldByName("Func")
}

Expand Down
10 changes: 5 additions & 5 deletions web/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ var (

// NewMultiServer returns new multi servers group
func NewMultiServer(params MultiServerParams) mserv.Server {
mserv.SetLogger(params.Logger)
return mserv.New(params.Servers...)
}

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

// NewHTTPServer creates http-server that will be embedded into multi-server
func NewHTTPServer(v *viper.Viper, key string, h http.Handler, l logger.StdLogger) ServerResult {
if h == nil {
switch {
case h == nil:
l.Printf("Empty handler for %s server, skip", key)
return ServerResult{}
} else if v.GetBool(key + ".disabled") {
case v.GetBool(key + ".disabled"):
l.Printf("Server %s disabled", key)
return ServerResult{}
} else if !v.IsSet(key + ".address") {
case !v.IsSet(key + ".address"):
l.Printf("Empty bind address for %s server, skip", key)
return ServerResult{}
}

l.Printf("Create %s http server, bind address: %s", key, v.GetString(key+".address"))
return ServerResult{
Server: mserv.NewHTTPServer(
v.GetDuration(key+".shutdown_timeout"),
&http.Server{
Addr: v.GetString(key + ".address"),
Handler: h,
Expand All @@ -123,5 +122,6 @@ func NewHTTPServer(v *viper.Viper, key string, h http.Handler, l logger.StdLogge
IdleTimeout: v.GetDuration(key + ".idle_timeout"),
MaxHeaderBytes: v.GetInt(key + ".max_header_bytes"),
},
mserv.HTTPShutdownTimeout(v.GetDuration(key+".shutdown_timeout")),
)}
}
4 changes: 2 additions & 2 deletions web/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestServers(t *testing.T) {

// Randomize ports:
for name := range servers {
servers[name], err = net.Listen("tcp", ":0")
servers[name], err = net.Listen("tcp", "127.0.0.1:0")
assert.NoError(err)
assert.NoError(servers[name].Close())

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

serve.Start()
assert.NoError(serve.Start())
})
assert.NoError(err)

Expand Down
14 changes: 12 additions & 2 deletions workers/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ const (
// ErrMissingKey when config key for worker is missing
ErrMissingKey = Error("missing worker key")

// ErrRedisClientNil when redis client not provided
ErrRedisClientNil = Error("gotten nil redis client for exclusive worker")
// ErrEmptyConfig when viper not passed to params
ErrEmptyConfig = Error("empty config")

// ErrEmptyWorkers when workers not passed to params
ErrEmptyWorkers = Error("empty workers")

// ErrEmptyLocker when locker required,
// but not passed to params
ErrEmptyLocker = Error("empty locker")

// ErrEmptyJob when worker job is nil
ErrEmptyJob = Error("empty job")
)

// Error converts constant error from string
Expand Down
24 changes: 24 additions & 0 deletions workers/errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package workers

import (
"testing"
)

func TestError_Error(t *testing.T) {
tests := []struct {
name string
e Error
want string
}{
{name: "empty error"},
{name: "custom error", e: Error("custom"), want: "custom"},
}
for i := range tests {
tt := tests[i]
t.Run(tt.name, func(t *testing.T) {
if got := tt.e.Error(); got != tt.want {
t.Errorf("Error() = %v, want %v", got, tt.want)
}
})
}
}
Loading

0 comments on commit 00e2cf2

Please sign in to comment.