Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Merge commit "fix: queue: switch from using a time based counter to a…
Browse files Browse the repository at this point in the history
… monotonic one"
  • Loading branch information
Jorropo committed Dec 9, 2022
2 parents ed88972 + 071d037 commit 01f1180
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
os:
- linux
- windows

language: go

Expand Down
7 changes: 4 additions & 3 deletions queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package queue
import (
"context"
"fmt"
"time"

cid "github.com/ipfs/go-cid"
datastore "github.com/ipfs/go-datastore"
namespace "github.com/ipfs/go-datastore/namespace"
Expand All @@ -29,6 +27,8 @@ type Queue struct {
enqueue chan cid.Cid
close context.CancelFunc
closed chan struct{}

counter int
}

// NewQueue creates a queue for cids
Expand Down Expand Up @@ -117,7 +117,8 @@ func (q *Queue) work() {

select {
case toQueue := <-q.enqueue:
keyPath := fmt.Sprintf("%d/%s", time.Now().UnixNano(), c.String())
keyPath := fmt.Sprintf("%063d/%s", q.counter, c.String())
q.counter++
nextKey := datastore.NewKey(keyPath)

if err := q.ds.Put(q.ctx, nextKey, toQueue.Bytes()); err != nil {
Expand Down

0 comments on commit 01f1180

Please # to comment.