Skip to content

Commit 85cf38e

Browse files
authored
Create pool if there is atleast one valid server (#10)
1 parent 757531e commit 85cf38e

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

consumer_pool.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package beanstalk
22

33
import (
44
"context"
5+
"errors"
56
"sync"
67
)
78

@@ -25,13 +26,15 @@ func NewConsumerPool(uris []string, tubes []string, config Config) (*ConsumerPoo
2526

2627
pool := &ConsumerPool{C: config.jobC, config: config, stop: make(chan struct{})}
2728
for _, uri := range multiply(uris, config.Multiply) {
29+
// Silently ignoring unsuccessful connections
2830
consumer, err := NewConsumer(uri, tubes, config)
29-
if err != nil {
30-
pool.Stop()
31-
return nil, err
31+
if err == nil {
32+
pool.consumers = append(pool.consumers, consumer)
3233
}
33-
34-
pool.consumers = append(pool.consumers, consumer)
34+
}
35+
if len(pool.consumers) == 0 {
36+
pool.Stop()
37+
return nil, errors.New("no valid consumers")
3538
}
3639

3740
return pool, nil

producer_pool.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package beanstalk
22

33
import (
44
"context"
5+
"errors"
56
"math/rand"
67
"sync"
78

@@ -24,13 +25,15 @@ func NewProducerPool(uris []string, config Config) (*ProducerPool, error) {
2425

2526
pool := &ProducerPool{config: config}
2627
for _, URI := range multiply(uris, config.Multiply) {
28+
// Silently ignoring unsuccessful connections
2729
producer, err := NewProducer(URI, config)
28-
if err != nil {
29-
pool.Stop()
30-
return nil, err
30+
if err == nil {
31+
pool.producers = append(pool.producers, producer)
3132
}
32-
33-
pool.producers = append(pool.producers, producer)
33+
}
34+
if len(pool.producers) == 0 {
35+
pool.Stop()
36+
return nil, errors.New("no available servers")
3437
}
3538

3639
return pool, nil

0 commit comments

Comments
 (0)