blob: 3e48a2d74175869ddde99fb92e764e6f1e1a040f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package beanstalk
import (
"fmt"
"github.com/spiral/roadrunner/service"
"strings"
"time"
)
// Config defines beanstalk broker configuration.
type Config struct {
// Addr of beanstalk server.
Addr string
// Timeout to allocate the connection. Default 10 seconds.
Timeout int
}
// Hydrate config values.
func (c *Config) Hydrate(cfg service.Config) error {
if err := cfg.Unmarshal(c); err != nil {
return err
}
if c.Addr == "" {
return fmt.Errorf("beanstalk address is missing")
}
return nil
}
// TimeoutDuration returns number of seconds allowed to allocate the connection.
func (c *Config) TimeoutDuration() time.Duration {
timeout := c.Timeout
if timeout == 0 {
timeout = 10
}
return time.Duration(timeout) * time.Second
}
// size creates new rpc socket Listener.
func (c *Config) newConn() (*conn, error) {
dsn := strings.Split(c.Addr, "://")
if len(dsn) != 2 {
return nil, fmt.Errorf("invalid socket DSN (tcp://localhost:11300, unix://beanstalk.sock)")
}
return newConn(dsn[0], dsn[1], c.TimeoutDuration())
}
|