func (tr *taskRunner) tryRecover(err error) error { log.Warning("try recover from ", err) tr.cleanupOutgoingTasks(err) //try to recover c, err := redisconn.NewConnection(tr.redisAddr, tr.netTimeout) if err != nil { tr.cleanupQueueTasks() //do not block dispatcher log.Warning(err) time.Sleep(1 * time.Second) return err } tr.c = c go tr.readloop() return nil }
func NewTaskRunner(addr string, netTimeout int) (*taskRunner, error) { tr := &taskRunner{ in: make(chan interface{}, 1000), out: make(chan interface{}, 1000), redisAddr: addr, tasks: list.New(), netTimeout: netTimeout, } c, err := redisconn.NewConnection(addr, netTimeout) if err != nil { return nil, err } tr.c = c go tr.writeloop() go tr.readloop() return tr, nil }