added function name and payload to id generation so that users can set up id generators that can generate duplicate ids for duplicate work, and gearman can then ignore that duplicate work

This commit is contained in:
wickning1 2014-05-20 15:16:38 -05:00
parent 9d7a29fe26
commit 0deaa25a0b
3 changed files with 6 additions and 6 deletions

View File

@ -192,7 +192,7 @@ func (client *Client) do(funcname string, data []byte,
handle = resp.Handle
mutex.Unlock()
}
id := IdGen.Id()
id := IdGen.Id(funcname, string(data))
req := getJob(id, []byte(funcname), data)
req.DataType = flag
client.write(req)

View File

@ -16,10 +16,10 @@ func init() {
IdGen = NewAutoIncId()
}
// ID generator interface. Users can implament this for
// ID generator interface. Users can implement this for
// their own generator.
type IdGenerator interface {
Id() string
Id(funcname, payload string) string
}
// AutoIncId
@ -27,7 +27,7 @@ type autoincId struct {
value int64
}
func (ai *autoincId) Id() string {
func (ai *autoincId) Id(funcname, payload string) string {
next := atomic.AddInt64(&ai.value, 1)
return strconv.FormatInt(next, 10)
}

View File

@ -7,9 +7,9 @@ import (
func TestAutoInc(t *testing.T) {
ai := NewAutoIncId()
previous := ai.Id()
previous := ai.Id("testfuncname", "fakepayload")
for i := 0; i < 10; i++ {
id := ai.Id()
id := ai.Id("testfuncname", "fakepayload2")
if id == previous {
t.Errorf("Id not unique, previous and current %s", id)
}