Skip to content

Commit

Permalink
Unstable (#28)
Browse files Browse the repository at this point in the history
* Fixed CPU usage caused by polling inboxes

* fixed padding in ggq

* README updates

* doc fix

* more doc updates and fixes

* fixed bug where processes did not cleanup when reaching max restarts

* Added SetOutput for the logger
  • Loading branch information
anthdm authored Mar 13, 2023
1 parent bae4cfa commit 7b48e18
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test: build
go test ./... --race
go test ./... -count=1 --race

proto:
protoc --go_out=. --go-vtproto_out=. --go_opt=paths=source_relative --proto_path=. actor/actor.proto
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ e.Spawn(newFoo, "foo",
)
```

## Listening to the Eventstream
## Subscribing and publishing to the Eventstream

```go
e := actor.NewEngine()

// Subscribe to a various list of event that are being broadcasted by
// the engine. But also published by you.
// Subscribe to a various list of events that are being broadcast by
// the engine.
// The eventstream can also be used to publish custom events and notify all of the subscribers..
eventSub := e.EventStream.Subscribe(func(event any) {
switch evt := event.(type) {
case *actor.DeadLetterEvent:
Expand Down Expand Up @@ -121,7 +122,7 @@ e.SpawnFunc(func(c *actor.Context) {
time.Sleep(time.Second)
```

## Customizing the PID separator
## Customizing the Engine

```Go
cfg := actor.Config{
Expand All @@ -132,7 +133,7 @@ e := actor.NewEngine(cfg)

After configuring the Engine with a custom PID Separator the string representation of PIDS will look like this:

```
```Go
pid := actor.NewPID("127.0.0.1:3000", "foo", "bar", "baz", "1")
// 127.0.0.1:3000->foo->bar->baz->1
```
Expand All @@ -147,15 +148,15 @@ For examples on how to implement custom middleware, check out the middleware fol

You can set the log level of Hollywoods log module:

```
```Go
import "github.com/anthdm/hollywood/log
log.SetLevel(log.LevelInfo)
```
To disable all logging
```
```Go
import "github.com/anthdm/hollywood/log

log.SetLevel(log.LevelPanic)
Expand Down
3 changes: 2 additions & 1 deletion actor/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (p *process) tryRestart(v any) {
log.Errorw(msg.From, log.M{
"error": msg.Err,
})
time.Sleep(restartDelay)
time.Sleep(restartDelay) // TODO: make this configurable
p.Start()
return
}
Expand All @@ -145,6 +145,7 @@ func (p *process) tryRestart(v any) {
"pid": p.pid,
"restarts": p.restarts,
})
p.cleanup(nil)
return
}
// Restart the process after its restartDelay
Expand Down
4 changes: 2 additions & 2 deletions examples/eventstream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ func main() {
wg := sync.WaitGroup{}
wg.Add(1)

// Subscribe to a various list of event that are being broadcasted by
// the engine. But also published by you.
// Subscribe to a various list of events that are being broadcast by
// the engine, but also published by you.
eventSub := e.EventStream.Subscribe(func(event any) {
switch evt := event.(type) {
case *actor.DeadLetterEvent:
Expand Down
1 change: 1 addition & 0 deletions ggq/ggq.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type GGQ[T any] struct {
state atomic.Uint32
_ [cacheLinePadding - unsafe.Sizeof(atomic.Uint32{})]byte
isIdling atomic.Bool
_ [cacheLinePadding - unsafe.Sizeof(atomic.Bool{})]byte
buffer []slot[T]
_ [cacheLinePadding]byte
mask uint32
Expand Down
10 changes: 9 additions & 1 deletion log/log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package log

import "github.com/sirupsen/logrus"
import (
"io"

"github.com/sirupsen/logrus"
)

type M map[string]any

Expand All @@ -16,6 +20,10 @@ const (
LevelPanic
)

func SetOutput(w io.Writer) {
logrus.SetOutput(w)
}

func SetLevel(level Level) {
var l logrus.Level
switch level {
Expand Down

0 comments on commit 7b48e18

Please sign in to comment.