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:
parent
9d7a29fe26
commit
0deaa25a0b
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user