File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import (
1111)
1212
1313const (
14- Version = "v4.1.6 "
14+ Version = "v4.1.7 "
1515
1616 HighestPriority = 255
1717 LowestPriority = - 255
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ require (
2626 github.com/vcraescu/go-paginator/v2 v2.0.0
2727 github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
2828 go.mongodb.org/mongo-driver v1.10.0
29- golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
29+ golang.org/x/net v0.0.0-20220708220712-1185a9018129
3030 golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
3131 golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
3232 golang.org/x/tools v0.1.5 // indirect
Original file line number Diff line number Diff line change @@ -3,13 +3,14 @@ package interfaces
33import (
44 "github.com/bimalabs/framework/v4/configs"
55 "github.com/bimalabs/framework/v4/messengers"
6+ "golang.org/x/net/context"
67)
78
89type Consumer struct {
910 Messenger * messengers.Messenger
1011}
1112
12- func (q * Consumer ) Run (servers []configs.Server ) {
13+ func (q * Consumer ) Run (ctx context. Context , servers []configs.Server ) {
1314 if q .Messenger == nil {
1415 return
1516 }
Original file line number Diff line number Diff line change @@ -2,12 +2,13 @@ package interfaces
22
33import (
44 "github.com/bimalabs/framework/v4/configs"
5+ "golang.org/x/net/context"
56)
67
78type Database struct {
89}
910
10- func (d * Database ) Run (servers []configs.Server ) {
11+ func (d * Database ) Run (ctx context. Context , servers []configs.Server ) {
1112 if configs .Database == nil {
1213 return
1314 }
Original file line number Diff line number Diff line change @@ -3,13 +3,14 @@ package interfaces
33import (
44 "github.com/bimalabs/framework/v4/configs"
55 "github.com/olivere/elastic/v7"
6+ "golang.org/x/net/context"
67)
78
89type Elasticsearch struct {
910 Client * elastic.Client
1011}
1112
12- func (e * Elasticsearch ) Run (servers []configs.Server ) {
13+ func (e * Elasticsearch ) Run (ctx context. Context , servers []configs.Server ) {
1314 if e .Client == nil {
1415 return
1516 }
Original file line number Diff line number Diff line change @@ -5,11 +5,12 @@ import (
55 "time"
66
77 "github.com/bimalabs/framework/v4/configs"
8+ "golang.org/x/net/context"
89)
910
1011type (
1112 Application interface {
12- Run (servers []configs.Server )
13+ Run (ctx context. Context , servers []configs.Server )
1314 IsBackground () bool
1415 Priority () int
1516 }
@@ -34,12 +35,15 @@ func (f *Factory) Run(servers []configs.Server) {
3435 return f .applications [i ].Priority () > f .applications [j ].Priority ()
3536 })
3637
38+ ctx , cancel := context .WithCancel (context .Background ())
3739 for _ , application := range f .applications {
3840 if application .IsBackground () {
39- go application .Run (servers )
41+ go application .Run (ctx , servers )
4042 } else {
4143 time .Sleep (100 * time .Millisecond )
42- application .Run (servers )
44+ application .Run (ctx , servers )
4345 }
4446 }
47+
48+ defer cancel ()
4549}
Original file line number Diff line number Diff line change 11package interfaces
22
33import (
4+ "context"
45 "log"
56 "net"
67 "strconv"
@@ -20,7 +21,7 @@ type GRpc struct {
2021 Debug bool
2122}
2223
23- func (g * GRpc ) Run (servers []configs.Server ) {
24+ func (g * GRpc ) Run (ctx context. Context , servers []configs.Server ) {
2425 var gRpcAddress strings.Builder
2526 gRpcAddress .WriteString (":" )
2627 gRpcAddress .WriteString (strconv .Itoa (g .GRpcPort ))
@@ -47,6 +48,13 @@ func (g *GRpc) Run(servers []configs.Server) {
4748 grpc .StreamInterceptor (grpc_middleware .ChainStreamServer (streams ... )),
4849 grpc .UnaryInterceptor (grpc_middleware .ChainUnaryServer (unaries ... )),
4950 )
51+ go func () {
52+ select {
53+ case <- ctx .Done ():
54+ gRpc .Stop ()
55+ }
56+
57+ }()
5058
5159 for _ , server := range servers {
5260 server .Register (gRpc )
You can’t perform that action at this time.
0 commit comments