chg: [input] error handling on creation

d4forward
Jean-Louis Huynen 2020-04-08 16:22:16 +02:00
parent 7a4ba5405e
commit 8ae509e0eb
No known key found for this signature in database
GPG Key ID: 64799157F4BD6B93
1 changed files with 6 additions and 6 deletions

View File

@ -3,7 +3,6 @@ package inputreader
import ( import (
"bytes" "bytes"
"io" "io"
"log"
"time" "time"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
@ -24,21 +23,23 @@ type RedisLPOPReader struct {
buf []byte buf []byte
} }
// NewLPOPReader creates a new RedisLPOPScanner // NewLPOPReader creates a new RedisLPOPReader
func NewLPOPReader(rc *redis.Conn, db int, queue string, rt int) *RedisLPOPReader { func NewLPOPReader(rc *redis.Conn, db int, queue string, rt int) (*RedisLPOPReader, error) {
rr := *rc rr := *rc
if _, err := rr.Do("SELECT", db); err != nil { if _, err := rr.Do("SELECT", db); err != nil {
rr.Close() rr.Close()
log.Fatal(err) return nil, err
} }
return &RedisLPOPReader{ r := &RedisLPOPReader{
r: rc, r: rc,
d: db, d: db,
q: queue, q: queue,
retryPeriod: time.Duration(rt) * time.Minute, retryPeriod: time.Duration(rt) * time.Minute,
} }
return r, nil
} }
// Read LPOP the redis queue and use a bytes reader to copy // Read LPOP the redis queue and use a bytes reader to copy
@ -51,7 +52,6 @@ func (rl *RedisLPOPReader) Read(p []byte) (n int, err error) {
if err == redis.ErrNil { if err == redis.ErrNil {
return 0, io.EOF return 0, io.EOF
} else if err != nil { } else if err != nil {
log.Println(err)
return 0, err return 0, err
} }
rreader := bytes.NewReader(buf) rreader := bytes.NewReader(buf)