Пример #1
0
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

}
Пример #2
0
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)
	}
}
Пример #3
0
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)
	}

}
Пример #4
0
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

}
Пример #5
0
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

}
Пример #6
0
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

}
Пример #7
0
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

}
Пример #8
0
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

}
Пример #9
0
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

}
Пример #10
0
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

	})

}
Пример #11
0
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

}