watcher

package module
v0.0.4-rc3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2023 License: Apache-2.0 Imports: 5 Imported by: 1

README

watcher any for Golang

Go Tests

Installation

go get github.com/goxtools/watcher@v0.0.1

Quickstart

for consumer [old version]
- ch := make(chan int, c.GetConsumerNumber())
- for {
-    ch <- 1
-    go func(channel chan int, c mq.Consumer) {
-        defer gorecover.GoRecover(context.Background(), c.GetConsumerName()+"job err")
-        ctx := new(Context)
-        if err := c.Consumer(ctx); err != nil {
-            <-channel
-            return
-        }
-        <-channel
-    }(ch, c)
-}
for consumer [watcher]
for i := 0; i < c.GetConsumerNumber(); i++{
    go func() {
        w := NewWatcher(10, time.Second*1, time.Second*10)
        w.On(func(args ...interface{}) {
            c.Consumer(new(Context))
        }
    }
}

Test Case

func TestWatcher(t *testing.T) {
    rand.Seed(time.Now().UnixNano())

    //	Retry 10 times, the retry interval is 1 second,
    //	after 10 seconds of stable operation,
    //	reset the number of retries
    w := NewWatcher(10, time.Second*1, time.Second*10)
    w.On(func(args ...interface{}) {
        for {
            if rand.Int()%9 == 0 {
                panic("crash")
            }
            time.Sleep(500 * time.Millisecond)
            fmt.Printf("%#v\n", w)
        }
    })
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher Listen for crashes, restart the service

func NewWatcher added in v0.0.2

func NewWatcher(retryTimes int32, delayTime time.Duration, resetTime time.Duration) *Watcher

func (*Watcher) On added in v0.0.2

func (w *Watcher) On(f func(args ...interface{}))

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL