func FlushCompletedJobs(binkey string) { key_done := "job:" + binkey + ":" + "done" var keys []string err := retry.Do(func() (err error) { keys, err = Redis_dispatch.Client.SMembers(key_done).Result() return }, func() { Redis_dispatch.InitClient() }) if err != nil { panic(err) } if len(keys) > 0 { DeleteHash(binkey, "args", keys) // DeleteHash(binkey, "results", keys) DeleteFromPending(binkey, keys) } return }
func AddToArgHash(binkey, jid, jinfo string) { key := "job:" + binkey + ":" + "args" err := retry.Do(func() (err error) { _, err = Redis.Client.HSet(key, jid, jinfo).Result() return }, func() { Redis.InitClient() }) if err != nil { panic(err) } }
func AddToPendingSet(binkey, jid string) { key := "job:" + binkey + ":" + "pending" err := retry.Do(func() (err error) { _, err = Redis.Client.SAdd(key, jid).Result() return }, func() { Redis.InitClient() }) if err != nil { panic(err) } }
func SetJobResult(binkey, jid, resultStr string) (val string) { key := "job:" + binkey + ":" + "results" err := retry.Do(func() (err error) { _, err = Redis_dispatch.Client.HSet(key, jid, resultStr).Result() return }, func() { Redis_dispatch.InitClient() }) if err != nil { panic(err) } return }
func DeleteHash(binkey, typeof string, jkey []string) { key := "job:" + binkey + ":" + typeof err := retry.Do(func() (err error) { _, err = Redis_dispatch.Client.HDel(key, jkey...).Result() return }, func() { Redis_dispatch.InitClient() }) if err != nil { panic(err) } return }
func DeleteFromPending(binkey string, jkey []string) { key := "job:" + binkey + ":" + "pending" err := retry.Do(func() (err error) { _, err = Redis_dispatch.Client.SRem(key, jkey...).Result() return }, func() { Redis_dispatch.InitClient() }) if err != nil { panic(err) } return }
func MoveJidToDoneSet(binkey, jid, keydone string) (val string) { key_process := "job:" + binkey + ":" + "processing" key_done := "job:" + binkey + ":" + keydone err := retry.Do(func() (err error) { _, err = Redis_dispatch.Client.SMove(key_process, key_done, jid).Result() return }, func() { Redis_dispatch.InitClient() }) if err != nil { panic(err) } return }
func MoveJidToProcessingSet(binkey, jid string) (val string) { key_pend := "job:" + binkey + ":" + "pending" key_process := "job:" + binkey + ":" + "processing" err := retry.Do(func() (err error) { _, err = Redis_fetch.Client.SMove(key_pend, key_process, jid).Result() return }, func() { Redis_fetch.InitClient() }) if err != nil { panic(err) } return }
func GetJobInfo(binkey, jid string) (val string) { key := "job:" + binkey + ":" + "args" err := retry.Do(func() (err error) { val, err = Redis_fetch.Client.HGet(key, jid).Result() if err == redis.Nil { err = nil val = "" } return }, func() { Redis_fetch.InitClient() }) if err != nil { panic(err) } return }
func TestRetrying(t *testing.T) { fmt.Println("Retry Test:") i := 0 retry.Do(func() error { switch i { case 3: return nil default: i = i + 1 return errors.New("Simulated Error") } return nil }) }
func GetPendingJids(binkey string) (val string) { key := "job:" + binkey + ":" + "pending" err := retry.Do(func() (err error) { val, err = Redis_fetch.Client.SRandMember(key).Result() if err == redis.Nil { err = nil val = "" return } return }, func() { Redis_fetch.InitClient() }) if err != nil { panic(err) } return }