From 0deaa25a0b30debe654451b9adf17cde5fd38080 Mon Sep 17 00:00:00 2001 From: wickning1 Date: Tue, 20 May 2014 15:16:38 -0500 Subject: [PATCH] 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 --- client/client.go | 2 +- client/id.go | 6 +++--- client/id_test.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/client.go b/client/client.go index 5e12dbb..5e019bf 100644 --- a/client/client.go +++ b/client/client.go @@ -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) diff --git a/client/id.go b/client/id.go index 4c92e99..1e7c43f 100644 --- a/client/id.go +++ b/client/id.go @@ -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) } diff --git a/client/id_test.go b/client/id_test.go index 399d217..d745380 100644 --- a/client/id_test.go +++ b/client/id_test.go @@ -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) }