@@ -3,6 +3,7 @@ package taskqueue
3
3
import (
4
4
"context"
5
5
"encoding/json"
6
+ "log"
6
7
"time"
7
8
8
9
"github.com/go-redis/redis/v8"
@@ -72,8 +73,7 @@ var enqueueCmd = redis.NewScript(`
72
73
return nil
73
74
end
74
75
75
- local task_id = redis.call("xadd", KEYS[2], "*", "id", ARGV[1], "data", ARGV[2])
76
- return task_id
76
+ return redis.call("xadd", KEYS[2], "*", "id", ARGV[1], "data", ARGV[2])
77
77
` )
78
78
79
79
func (q * taskQueue [T ]) Enqueue (ctx context.Context , id string , data * T ) (* string , error ) {
@@ -148,17 +148,20 @@ func (q *taskQueue[T]) Extend(ctx context.Context, taskID string) error {
148
148
// KEYS[1] = set
149
149
// KEYS[2] = stream
150
150
// ARGV[1] = task id
151
+ // ARGV[2] = group
152
+ // We have to XACK _and_ XDEL here. See https://github.com/redis/redis/issues/5754
151
153
var completeCmd = redis .NewScript (`
152
154
local task = redis.call("XRANGE", KEYS[2], ARGV[1], ARGV[1])
153
155
local id = task[1][2][2]
154
156
redis.call("SREM", KEYS[1], id)
157
+ redis.call("XACK", KEYS[2], ARGV[2], ARGV[1])
155
158
return redis.call("XDEL", KEYS[2], ARGV[1])
156
159
` )
157
160
158
161
func (q * taskQueue [T ]) Complete (ctx context.Context , taskID string ) error {
159
162
// Delete the task here. Overall we'll keep the stream at a small size, so fragmentation
160
163
// is not an issue for us.
161
- c , err := completeCmd .Run (ctx , q .rdb , []string {q .setKey , q .streamKey }, taskID ).Result ()
164
+ c , err := completeCmd .Run (ctx , q .rdb , []string {q .setKey , q .streamKey }, taskID , q . groupName ).Result ()
162
165
if err != nil && err != redis .Nil {
163
166
return errors .Wrap (err , "could not complete task" )
164
167
}
@@ -167,6 +170,8 @@ func (q *taskQueue[T]) Complete(ctx context.Context, taskID string) error {
167
170
return errors .New ("could find task to complete" )
168
171
}
169
172
173
+ log .Println ("Completing activity task" , taskID )
174
+
170
175
return nil
171
176
}
172
177
0 commit comments