Skip to content

Commit

Permalink
Update ReadMe (#16)
Browse files Browse the repository at this point in the history
Update ReadMe
  • Loading branch information
glebnaz authored Nov 28, 2023
1 parent dd1fda7 commit a1245fa
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,52 +45,67 @@ package main

import (
"context"
"os"
"sync"
"time"

"github.com/glebnaz/witcher/db/mongo"
"github.com/glebnaz/witcher/engine"
"github.com/glebnaz/witcher/grpc"
wlog "github.com/glebnaz/witcher/log"
"github.com/rs/zerolog/log"
)

func main() {
log.SetLevel(log.DebugLevel)
log.SetFormatter(&log.TextFormatter{
DisableColors: false,
})
wlog.InitLog(os.Stdout, false)
serverGRPC := grpc.NewDefaultServer("witcher_example")
s := engine.NewServer(engine.WithGRPCServer(serverGRPC, ":8082", time.Second*5))

s := engine.NewServer()
checker1 := engine.NewDefaultChecker("checker false", func() error {
log.Info().Msgf("Checker1 is running")
return nil
})

checker := engine.NewDefaultChecker("checker", func() error {
log.Infof("Checker is running")
checker2 := engine.NewDefaultChecker("checker true", func() error {
log.Info().Msgf("Checker2 is running")
return nil
})

closer := engine.NewDefaultCloser("closer", func(ctx context.Context, wg *sync.WaitGroup) error {
log.Infof("Closer is running")
log.Info().Msgf("Closer is running")
time.Sleep(time.Second * 10)
log.Infof("Closer is running after 10 seconds")
log.Info().Msgf("Closer is running after 10 seconds")
wg.Done()
return nil
})

s.AddChecker(checker)
s.AddCheckers([]engine.Checker{checker1, checker2})
s.AddCloser(closer)
s.AddActor(func() error {
i := 0
for {
i++
log.Debugf("Actor is running %d", i)
log.Debug().Msgf("Actor is running %d", i)
time.Sleep(time.Second * 1)
}
},
func(error) {
log.Errorf("Actor failed")
log.Error().Msg("Actor failed")
})

m, err := mongo.NewMongo(s.GetCTX(), "mongodb://localhost:27017")
if err != nil {
log.Error().Msgf("Error connect to mongo: %s", err)
}

s.AddCloser(m.Closer())
s.AddChecker(m.HealthChecker(time.Second * 5))

if err := s.Run(); err != nil {
log.Errorf("Error Run Server: %s", err)
log.Error().Msgf("Error Run Server: %s", err)
}
}

```

## Debug Server
Expand Down

0 comments on commit a1245fa

Please sign in to comment.