diff options
author | Valery Piashchynski <[email protected]> | 2021-07-20 18:02:31 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-07-20 18:02:31 +0300 |
commit | 50cf036c81668508c8f2e9130bc5a2019cddf1b9 (patch) | |
tree | 053ee60a6fb02b5cdbc964fba64f34e1de3d4032 /plugins/jobs/drivers/beanstalk/redial.go | |
parent | a149f8345056144f0b62af9b7344fc2628e7fe90 (diff) |
Beanstalk driver alpha version ready.
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/jobs/drivers/beanstalk/redial.go')
-rw-r--r-- | plugins/jobs/drivers/beanstalk/redial.go | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/plugins/jobs/drivers/beanstalk/redial.go b/plugins/jobs/drivers/beanstalk/redial.go index c9e72ad8..e1922517 100644 --- a/plugins/jobs/drivers/beanstalk/redial.go +++ b/plugins/jobs/drivers/beanstalk/redial.go @@ -1,3 +1,31 @@ package beanstalk -func (j *JobConsumer) redial() {} +import ( + "sync/atomic" + + "github.com/beanstalkd/go-beanstalk" +) + +func (j *JobConsumer) redial() { + for range j.reconnectCh { + // backoff here + + j.Lock() + + var err error + j.conn, err = beanstalk.DialTimeout(j.network, j.addr, j.tout) + if err != nil { + panic(err) + } + + j.tube = beanstalk.NewTube(j.conn, j.tName) + j.tubeSet = beanstalk.NewTubeSet(j.conn, j.tName) + + // restart listener + if atomic.LoadUint32(&j.listeners) == 1 { + go j.listen() + } + + j.Unlock() + } +} |