Skip to content

Commit 74d079e

Browse files
bors[bot]Valery Piashchynski
andauthored
Merge #50
50: Feature/print graph r=48d90782 a=48d90782 resolves #49 At the moment Windows is not supported for this feature, because there is no GCC on Windows. But, it is possible (and I tested this scenario) to use this feature on Windows. Steps: 1. Copy PrintGraph function from print_graph.go file to the print_graph_windows.go. 2. Install https://jmeubank.github.io/tdm-gcc/ (GCC for windows). At the moment we can't pack `tdm-gcc` with Endure to support windows, unfortunately. 3. Enjoy :) OR 1. Use WSL2 In the near future, I'll provide a cross-platform solution. Co-authored-by: Valery Piashchynski <piashchynski_valery@hotmail.com>
2 parents 297b735 + bc9d67c commit 74d079e

File tree

42 files changed

+167
-399
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+167
-399
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
<p align="center">
33
<a href="https://pkg.go.dev/github.com/spiral/Endure?tab=doc"><img src="https://godoc.org/github.com/spiral/Endure?status.svg"></a>
44
<a href="https://github.com/spiral/Endure/actions"><img src="https://github.com/spiral/Endure/workflows/CI/badge.svg" alt=""></a>
5-
<a href="https://goreportcard.com/report/github.com/spiral/Endure"><img src="https://goreportcard.com/badge/github.com/spiral/Endure"></a>
6-
<a href="https://codecov.io/gh/spiral/Endure/"><img src="https://codecov.io/gh/spiral/Endure/branch/master/graph/badge.svg"></a>
5+
<a href="https://codecov.io/gh/spiral/endure"><img src="https://codecov.io/gh/spiral/endure/branch/master/graph/badge.svg?token=itNaiZ6ALN"/></a>
76
<a href="https://discord.gg/TFeEmCs"><img src="https://img.shields.io/badge/discord-chat-magenta.svg"></a>
87
<a href="https://lgtm.com/projects/g/spiral/endure/alerts/"><img src="https://img.shields.io/lgtm/alerts/g/spiral/endure.svg?logo=lgtm&logoWidth=18"></a>
98
</p>

container.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ package endure
33
// InitMethodName is the function name for the reflection
44
const InitMethodName = "Init"
55

6-
// ConfigureMethodName
7-
const ConfigureMethodName = "Configure"
8-
9-
// CloseMethodName
10-
const CloseMethodName = "Close"
11-
126
// ServeMethodName
137
const ServeMethodName = "Serve"
148

@@ -37,13 +31,6 @@ type result struct {
3731
}
3832

3933
type (
40-
// used to gracefully stop and configure the plugins
41-
graceful interface {
42-
// Configure is used when we need to make preparation and wait for all services till Serve
43-
Configure() error
44-
// Close frees resources allocated by the service
45-
Close() error
46-
}
4734
// this is the main service interface with should implement every plugin
4835
Service interface {
4936
// Serve

endure.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ type Endure struct {
5454
retry bool
5555
maxInterval time.Duration
5656
initialInterval time.Duration
57+
// option to visualize resulted (before init) graph
58+
visualize bool
5759

5860
mutex *sync.RWMutex
5961

@@ -168,6 +170,12 @@ func SetBackoffTimes(initialInterval time.Duration, maxInterval time.Duration) O
168170
}
169171
}
170172

173+
func Visualize(print bool) Options {
174+
return func(endure *Endure) {
175+
endure.visualize = print
176+
}
177+
}
178+
171179
// Depender depends the dependencies
172180
// name is a name of the dependency, for example - S2
173181
// vertex is a value -> pointer to the structure
@@ -212,10 +220,20 @@ func (e *Endure) Register(vertex interface{}) error {
212220
func (e *Endure) Init() error {
213221
const op = errors.Op("Init")
214222
// traverse the graph
215-
if err := e.addEdges(); err != nil {
223+
err := e.addEdges()
224+
if err != nil {
216225
return errors.E(op, errors.Init, err)
217226
}
218227

228+
// if failed - continue, just send warning to a user
229+
// visualize is not critical
230+
if e.visualize {
231+
err = structures.Visualize(e.graph.Vertices)
232+
if err != nil {
233+
e.logger.Warn("failed to visualize the graph", zap.Error(err))
234+
}
235+
}
236+
219237
// we should build init list in the reverse order
220238
sorted, err := structures.TopologicalSort(e.graph.Vertices)
221239
if err != nil {
@@ -251,33 +269,16 @@ func (e *Endure) Serve() (<-chan *Result, error) {
251269
const op = errors.Op("Serve")
252270
e.startMainThread()
253271

272+
// simple check that we have at least one vertex in the graph to Serve
254273
atLeastOne := false
255-
// call configure
256-
nCopy := e.runList.Head
257274

258-
// DEPRECATED TODO
275+
nCopy := e.runList.Head
259276
for nCopy != nil {
260277
if nCopy.Vertex.IsDisabled {
261278
nCopy = nCopy.Next
262279
continue
263280
}
264281
atLeastOne = true
265-
// deprecated
266-
err := e.configure(nCopy)
267-
if err != nil {
268-
e.logger.Error("backoff failed", zap.String("vertex id", nCopy.Vertex.ID), zap.Error(err))
269-
return nil, errors.E(op, errors.Serve, err)
270-
}
271-
272-
nCopy = nCopy.Next
273-
}
274-
275-
nCopy = e.runList.Head
276-
for nCopy != nil {
277-
if nCopy.Vertex.IsDisabled {
278-
nCopy = nCopy.Next
279-
continue
280-
}
281282
err := e.serve(nCopy)
282283
if err != nil {
283284
return nil, errors.E(op, errors.Serve, err)

errors/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const (
4545
ArgType
4646
Init
4747
Serve
48+
Unsupported
4849
Disabled
4950

5051
Traverse
@@ -73,6 +74,8 @@ func (k Kind) String() string {
7374
return "Traverse error"
7475
case FunctionCall:
7576
return "Function call error"
77+
case Unsupported:
78+
return "Unsupported"
7679
default:
7780
return "UNDEF"
7881
}

examples/sample_1/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
examples_bolt_db

examples/sample_1/go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
module github.com/spiral/endure/examples/db_http_logger
22

3-
go 1.14
3+
go 1.15
44

55
require (
66
github.com/NYTimes/gziphandler v1.1.1
77
github.com/gorilla/mux v1.7.4
88
github.com/rs/cors v1.7.0
9-
github.com/spiral/endure v1.0.0-beta6
9+
github.com/spiral/endure v1.0.0-beta9
1010
go.etcd.io/bbolt v1.3.5
1111
)
12+
13+
replace github.com/spiral/endure v1.0.0-beta9 => /home/valery/Projects/opensource/spiral/endure

examples/sample_1/go.sum

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,32 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
33
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
44
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
5-
github.com/cenkalti/backoff/v4 v4.0.2 h1:JIufpQLbh4DkbQoii76ItQIUFzevQSqOLZca4eamEDs=
6-
github.com/cenkalti/backoff/v4 v4.0.2/go.mod h1:eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg=
5+
github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm4fSc=
6+
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
7+
github.com/corona10/goimagehash v1.0.2 h1:pUfB0LnsJASMPGEZLj7tGY251vF+qLGqOgEP4rUs6kA=
8+
github.com/corona10/goimagehash v1.0.2/go.mod h1:/l9umBhvcHQXVtQO1V6Gp1yD20STawkhRnnX0D1bvVI=
79
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
810
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
911
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1012
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13+
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
14+
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
15+
github.com/goccy/go-graphviz v0.0.8 h1:hYQikvj368s8+rmfzFOZeiCXvSocGH7rfAyLTOy/7AM=
16+
github.com/goccy/go-graphviz v0.0.8/go.mod h1:wXVsXxmyMQU6TN3zGRttjNn3h+iCAS7xQFC6TlNvLhk=
17+
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
18+
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
1119
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
1220
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
1321
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
22+
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
1423
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
1524
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
1625
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
1726
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
1827
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
1928
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
29+
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY=
30+
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
2031
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
2132
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
2233
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -25,8 +36,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
2536
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
2637
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
2738
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
28-
github.com/spiral/endure v1.0.0-beta6 h1:Kl8xHM/7sSCfpaBndJnJ1zaHVcEeug05OeiemauczwA=
29-
github.com/spiral/endure v1.0.0-beta6/go.mod h1:ZqOMVUfVNlUKzhO3WpbqTqV4q4fKOJG8qCyqBYvmL6g=
3039
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
3140
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
3241
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
@@ -41,10 +50,14 @@ go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
4150
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
4251
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
4352
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
44-
go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
45-
go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
53+
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
54+
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
4655
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
4756
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
57+
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
58+
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
59+
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM=
60+
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
4861
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
4962
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
5063
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
@@ -67,6 +80,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
6780
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
6881
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6982
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
83+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
7084
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
7185
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
7286
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

examples/sample_1/graph.png

26.4 KB
Loading

examples/sample_1/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"os"
55
"os/signal"
6+
"syscall"
67

78
"github.com/spiral/endure"
89
"github.com/spiral/endure/examples/db_http_logger/modules/db"
@@ -13,7 +14,7 @@ import (
1314
)
1415

1516
func main() {
16-
container, err := endure.NewContainer(endure.DebugLevel, endure.RetryOnFail(true))
17+
container, err := endure.NewContainer(endure.DebugLevel, endure.RetryOnFail(true), endure.Visualize(true))
1718
if err != nil {
1819
panic(err)
1920
}
@@ -49,13 +50,13 @@ func main() {
4950
}
5051

5152
// stop by CTRL+C
52-
c := make(chan os.Signal)
53-
signal.Notify(c, os.Interrupt)
53+
c := make(chan os.Signal, 1)
54+
signal.Notify(c, os.Interrupt, syscall.SIGKILL, syscall.SIGINT)
5455

5556
for {
5657
select {
5758
case e := <-errCh:
58-
println(e.Error.Err.Error())
59+
println(e.Error.Error())
5960
er := container.Stop()
6061
if er != nil {
6162
panic(er)

examples/sample_1/modules/db/db_layer.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Repository interface {
2121
func (db *DB) Init(logger logger.SuperLogger) error {
2222
logger.SuperLogToStdOut("initializing DB")
2323
db.logger = logger
24-
db.path = "./examples"
24+
db.path = "./examples_bolt_db"
2525
bdb, err := bolt.Open(db.path, 0666, nil)
2626
if err != nil {
2727
return err
@@ -37,17 +37,8 @@ func (db *DB) Serve() chan error {
3737
return errCh
3838
}
3939

40-
func (db *DB) Configure() error {
41-
db.logger.SuperLogToStdOut("configuring DB")
42-
return nil
43-
}
44-
45-
func (db *DB) Close() error {
46-
return db.boltdb.Close()
47-
}
48-
4940
func (db *DB) Stop() error {
50-
return nil
41+
return db.boltdb.Close()
5142
}
5243

5344
func (db *DB) Name() string {

0 commit comments

Comments
 (0)