diff --git a/cluster/cluster.go b/cluster/cluster.go index efe12fe..dbaa5e5 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -10,8 +10,6 @@ import ( "github.com/google/uuid" ) -var requestTimeout = time.Second - // Producer is a function that can produce an actor.Producer. // Pretty simple, but yet powerfull tool to construct receivers // depending on Cluster. @@ -27,11 +25,13 @@ type Config struct { ActivationStrategy ActivationStrategy Engine *actor.Engine ClusterProvider Producer + RequestTimeout time.Duration } type Cluster struct { - id string - region string + id string + region string + requestTimeout time.Duration provider Producer engine *actor.Engine @@ -61,6 +61,9 @@ func New(cfg Config) (*Cluster, error) { if len(cfg.Region) == 0 { cfg.Region = "default" } + if cfg.RequestTimeout == 0 { + cfg.RequestTimeout = time.Second + } return &Cluster{ id: cfg.ID, region: cfg.Region, @@ -68,6 +71,7 @@ func New(cfg Config) (*Cluster, error) { engine: cfg.Engine, kinds: []kind{}, activationStrategy: cfg.ActivationStrategy, + requestTimeout: cfg.RequestTimeout, }, nil } @@ -109,7 +113,7 @@ func (c *Cluster) Activate(kind string, config *ActivationConfig) *actor.PID { id: config.ID, region: config.Region, } - resp, err := c.engine.Request(c.agentPID, msg, requestTimeout).Result() + resp, err := c.engine.Request(c.agentPID, msg, c.requestTimeout).Result() if err != nil { slog.Error("activation failed", "err", err) return nil @@ -155,7 +159,7 @@ func (c *Cluster) HasKindLocal(name string) bool { // Members returns all the members that are part of the cluster. func (c *Cluster) Members() []*Member { - resp, err := c.engine.Request(c.agentPID, getMembers{}, requestTimeout).Result() + resp, err := c.engine.Request(c.agentPID, getMembers{}, c.requestTimeout).Result() if err != nil { return []*Member{} } @@ -168,7 +172,7 @@ func (c *Cluster) Members() []*Member { // HasKind returns true whether the given kind is available for activation on // the cluster. func (c *Cluster) HasKind(name string) bool { - resp, err := c.engine.Request(c.agentPID, getKinds{}, requestTimeout).Result() + resp, err := c.engine.Request(c.agentPID, getKinds{}, c.requestTimeout).Result() if err != nil { return false } @@ -183,7 +187,7 @@ func (c *Cluster) HasKind(name string) bool { } func (c *Cluster) GetActivated(id string) *actor.PID { - resp, err := c.engine.Request(c.agentPID, getActive{id: id}, requestTimeout).Result() + resp, err := c.engine.Request(c.agentPID, getActive{id: id}, c.requestTimeout).Result() if err != nil { return nil } diff --git a/examples/cluster/member_1/main.go b/examples/cluster/member_1/main.go index 19fdc26..cc29fb3 100644 --- a/examples/cluster/member_1/main.go +++ b/examples/cluster/member_1/main.go @@ -2,6 +2,7 @@ package main import ( "log" + "time" "github.com/anthdm/hollywood/actor" "github.com/anthdm/hollywood/cluster" @@ -22,6 +23,7 @@ func main() { Region: "eu-west", ClusterProvider: cluster.NewSelfManagedProvider(), ActivationStrategy: shared.RegionBasedActivationStrategy("eu-west"), + RequestTimeout: time.Second, }) if err != nil { log.Fatal(err) diff --git a/examples/cluster/member_2/main.go b/examples/cluster/member_2/main.go index ebb3713..91609a5 100644 --- a/examples/cluster/member_2/main.go +++ b/examples/cluster/member_2/main.go @@ -2,6 +2,7 @@ package main import ( "log" + "time" "github.com/anthdm/hollywood/actor" "github.com/anthdm/hollywood/cluster" @@ -26,6 +27,7 @@ func main() { Region: "us-west", ClusterProvider: cluster.NewSelfManagedProvider(bootstrapAddr), ActivationStrategy: shared.RegionBasedActivationStrategy("eu-west"), + RequestTimeout: time.Second, }) if err != nil { log.Fatal(err)