]> source.dussan.org Git - gitea.git/commitdiff
upgrade levelqueue to 0.1.0 (#9192)
authorLunny Xiao <xiaolunwen@gmail.com>
Thu, 28 Nov 2019 15:37:33 +0000 (23:37 +0800)
committerGitHub <noreply@github.com>
Thu, 28 Nov 2019 15:37:33 +0000 (23:37 +0800)
19 files changed:
go.mod
go.sum
modules/indexer/issues/queue_disk.go
vendor/gitea.com/lunny/levelqueue/.drone.yml [new file with mode: 0644]
vendor/gitea.com/lunny/levelqueue/.gitignore [new file with mode: 0644]
vendor/gitea.com/lunny/levelqueue/LICENSE [new file with mode: 0644]
vendor/gitea.com/lunny/levelqueue/README.md [new file with mode: 0644]
vendor/gitea.com/lunny/levelqueue/error.go [new file with mode: 0644]
vendor/gitea.com/lunny/levelqueue/go.mod [new file with mode: 0644]
vendor/gitea.com/lunny/levelqueue/go.sum [new file with mode: 0644]
vendor/gitea.com/lunny/levelqueue/queue.go [new file with mode: 0644]
vendor/github.com/lunny/levelqueue/.gitignore [deleted file]
vendor/github.com/lunny/levelqueue/LICENSE [deleted file]
vendor/github.com/lunny/levelqueue/README.md [deleted file]
vendor/github.com/lunny/levelqueue/error.go [deleted file]
vendor/github.com/lunny/levelqueue/go.mod [deleted file]
vendor/github.com/lunny/levelqueue/go.sum [deleted file]
vendor/github.com/lunny/levelqueue/queue.go [deleted file]
vendor/modules.txt

diff --git a/go.mod b/go.mod
index 8547c734d5b153c8af1b3dea4c90c85e09b06000..a68eddf0cf001742f09a4af4a50d7e767a64ad74 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -4,6 +4,7 @@ go 1.13
 
 require (
        cloud.google.com/go v0.45.0 // indirect
+       gitea.com/lunny/levelqueue v0.1.0
        gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b
        gitea.com/macaron/cache v0.0.0-20190822004001-a6e7fee4ee76
        gitea.com/macaron/captcha v0.0.0-20190822015246-daa973478bae
@@ -59,7 +60,6 @@ require (
        github.com/lafriks/xormstore v1.3.2
        github.com/lib/pq v1.2.0
        github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96
-       github.com/lunny/levelqueue v0.0.0-20190217115915-02b525a4418e
        github.com/mailru/easyjson v0.7.0 // indirect
        github.com/markbates/goth v1.56.0
        github.com/mattn/go-isatty v0.0.7
diff --git a/go.sum b/go.sum
index 3aa74d8d9798bf17f8e58c9081a2d1dab22c4e2b..dd4ee71ac0447ade45616f5ec2a5fef5b0e91e38 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -10,6 +10,8 @@ cloud.google.com/go v0.45.0 h1:bALuGBSgE+BD4rxsopAYlqjcwqcQtye6pWG4bC3N/k0=
 cloud.google.com/go v0.45.0/go.mod h1:452BcPOeI9AZfbvDw0Tbo7D32wA+WX9WME8AZwMEDZU=
 cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
 cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
+gitea.com/lunny/levelqueue v0.1.0 h1:7wMk0VH6mvKN6vZEZCy9nUDgRmdPLgeNrm1NkW8EHNk=
+gitea.com/lunny/levelqueue v0.1.0/go.mod h1:G7hVb908t0Bl0uk7zGSg14fyzNtxgtD9Shf04wkMK7s=
 gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b h1:vXt85uYV17KURaUlhU7v4GbCShkqRZDSfo0TkC0YCjQ=
 gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b/go.mod h1:Cxadig6POWpPYYSfg23E7jo35Yf0yvsdC1lifoKWmPo=
 gitea.com/macaron/cache v0.0.0-20190822004001-a6e7fee4ee76 h1:mMsMEg90c5KXQgRWsH8D6GHXfZIW1RAe5S9VYIb12lM=
@@ -361,8 +363,6 @@ github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0=
 github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
 github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96 h1:uNwtsDp7ci48vBTTxDuwcoTXz4lwtDTe7TjCQ0noaWY=
 github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96/go.mod h1:mmIfjCSQlGYXmJ95jFN84AkQFnVABtKuJL8IrzwvUKQ=
-github.com/lunny/levelqueue v0.0.0-20190217115915-02b525a4418e h1:GSprKUrG9wNgwQgROvjPGXmcZrg4OLslOuZGB0uJjx8=
-github.com/lunny/levelqueue v0.0.0-20190217115915-02b525a4418e/go.mod h1:rQZVENnBOiVakCs97XvclbwJRTAv77CRFWcYVNDkVf8=
 github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de h1:nyxwRdWHAVxpFcDThedEgQ07DbcRc5xgNObtbTp76fk=
 github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de/go.mod h1:3q8WtuPQsoRbatJuy3nvq/hRSvuBJrHHr+ybPPiNvHQ=
 github.com/lunny/nodb v0.0.0-20160621015157-fc1ef06ad4af h1:UaWHNBdukWrSG3DRvHFR/hyfg681fceqQDYVTBncKfQ=
index b127f8d26977133a2af27dc2f1d1e2e730e2d7a7..d6187f2acbd022f72fb22ca2e96d28a15d90e6a4 100644 (file)
@@ -10,7 +10,7 @@ import (
 
        "code.gitea.io/gitea/modules/log"
 
-       "github.com/lunny/levelqueue"
+       "gitea.com/lunny/levelqueue"
 )
 
 var (
diff --git a/vendor/gitea.com/lunny/levelqueue/.drone.yml b/vendor/gitea.com/lunny/levelqueue/.drone.yml
new file mode 100644 (file)
index 0000000..883b796
--- /dev/null
@@ -0,0 +1,23 @@
+---
+kind: pipeline
+name: test
+
+workspace:
+  base: /go
+  path: src/gitea.com/lunny/levelqueue
+
+steps:
+- name: test
+  pull: default
+  image: golang:1.13
+  commands:
+  - go get -t -d -v ./...
+  - go build -v
+  - go test -v -race -coverprofile=coverage.txt -covermode=atomic
+  environment:
+    GO111MODULE: "on"
+    GOPROXY: https://goproxy.cn
+  when:
+    event:
+    - push
+    - pull_request
\ No newline at end of file
diff --git a/vendor/gitea.com/lunny/levelqueue/.gitignore b/vendor/gitea.com/lunny/levelqueue/.gitignore
new file mode 100644 (file)
index 0000000..59a8bde
--- /dev/null
@@ -0,0 +1,3 @@
+queue/
+queue_pop/
+queue_push/
\ No newline at end of file
diff --git a/vendor/gitea.com/lunny/levelqueue/LICENSE b/vendor/gitea.com/lunny/levelqueue/LICENSE
new file mode 100644 (file)
index 0000000..4a5a4ea
--- /dev/null
@@ -0,0 +1,19 @@
+Copyright (c) 2019 Lunny Xiao
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/vendor/gitea.com/lunny/levelqueue/README.md b/vendor/gitea.com/lunny/levelqueue/README.md
new file mode 100644 (file)
index 0000000..80a0853
--- /dev/null
@@ -0,0 +1,28 @@
+# levelqueue
+
+Level queue is a simple queue golang library base on go-leveldb.
+
+[![Build Status](https://drone.gitea.com/api/badges/lunny/levelqueue/status.svg)](https://drone.gitea.com/lunny/levelqueue)  [![](http://gocover.io/_badge/gitea.com/lunny/levelqueue)](http://gocover.io/gitea.com/lunny/levelqueue)
+[![](https://goreportcard.com/badge/gitea.com/lunny/levelqueue)](https://goreportcard.com/report/gitea.com/lunny/levelqueue)
+
+## Installation
+
+```
+go get gitea.com/lunny/levelqueue
+```
+
+## Usage
+
+```Go
+queue, err := levelqueue.Open("./queue")
+
+err = queue.RPush([]byte("test"))
+
+// pop an element from left of the queue
+data, err = queue.LPop()
+
+// if handle success, element will be pop, otherwise it will be keep
+queue.LHandle(func(dt []byte) error{
+    return nil
+})
+```
\ No newline at end of file
diff --git a/vendor/gitea.com/lunny/levelqueue/error.go b/vendor/gitea.com/lunny/levelqueue/error.go
new file mode 100644 (file)
index 0000000..d639c5d
--- /dev/null
@@ -0,0 +1,12 @@
+// Copyright 2019 Lunny Xiao. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package levelqueue
+
+import "errors"
+
+var (
+       // ErrNotFound means no element in queue
+       ErrNotFound = errors.New("no key found")
+)
diff --git a/vendor/gitea.com/lunny/levelqueue/go.mod b/vendor/gitea.com/lunny/levelqueue/go.mod
new file mode 100644 (file)
index 0000000..8b3e565
--- /dev/null
@@ -0,0 +1,8 @@
+module gitea.com/lunny/levelqueue
+
+require (
+       github.com/stretchr/testify v1.3.0
+       github.com/syndtr/goleveldb v0.0.0-20190203031304-2f17a3356c66
+)
+
+go 1.13
diff --git a/vendor/gitea.com/lunny/levelqueue/go.sum b/vendor/gitea.com/lunny/levelqueue/go.sum
new file mode 100644 (file)
index 0000000..7ae1873
--- /dev/null
@@ -0,0 +1,38 @@
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
+github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
+github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
+github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
+github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
+github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
+github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
+github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
+github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
+github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
+github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
+github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/syndtr/goleveldb v0.0.0-20190203031304-2f17a3356c66 h1:AwmkkZT+TucFotNCL+aNJ/0KCMsRtlXN9fs8uoOMSRk=
+github.com/syndtr/goleveldb v0.0.0-20190203031304-2f17a3356c66/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
+golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
+golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
+golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
+gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
+gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
+gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
+gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
+gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/vendor/gitea.com/lunny/levelqueue/queue.go b/vendor/gitea.com/lunny/levelqueue/queue.go
new file mode 100644 (file)
index 0000000..af624db
--- /dev/null
@@ -0,0 +1,263 @@
+// Copyright 2019 Lunny Xiao. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package levelqueue
+
+import (
+       "bytes"
+       "encoding/binary"
+       "sync"
+
+       "github.com/syndtr/goleveldb/leveldb"
+)
+
+// Queue defines a queue struct
+type Queue struct {
+       db       *leveldb.DB
+       highLock sync.Mutex
+       lowLock  sync.Mutex
+       low      int64
+       high     int64
+}
+
+// Open opens a queue object or create it if not exist
+func Open(dataDir string) (*Queue, error) {
+       db, err := leveldb.OpenFile(dataDir, nil)
+       if err != nil {
+               return nil, err
+       }
+
+       var queue = &Queue{
+               db: db,
+       }
+       queue.low, err = queue.readID(lowKey)
+       if err == leveldb.ErrNotFound {
+               queue.low = 1
+               err = db.Put(lowKey, id2bytes(1), nil)
+       }
+       if err != nil {
+               return nil, err
+       }
+
+       queue.high, err = queue.readID(highKey)
+       if err == leveldb.ErrNotFound {
+               err = db.Put(highKey, id2bytes(0), nil)
+       }
+       if err != nil {
+               return nil, err
+       }
+
+       return queue, nil
+}
+
+func (queue *Queue) readID(key []byte) (int64, error) {
+       bs, err := queue.db.Get(key, nil)
+       if err != nil {
+               return 0, err
+       }
+       return bytes2id(bs)
+}
+
+var (
+       lowKey  = []byte("low")
+       highKey = []byte("high")
+)
+
+func (queue *Queue) highincrement() (int64, error) {
+       id := queue.high + 1
+       queue.high = id
+       err := queue.db.Put(highKey, id2bytes(queue.high), nil)
+       if err != nil {
+               queue.high = queue.high - 1
+               return 0, err
+       }
+       return id, nil
+}
+
+func (queue *Queue) highdecrement() (int64, error) {
+       queue.high = queue.high - 1
+       err := queue.db.Put(highKey, id2bytes(queue.high), nil)
+       if err != nil {
+               queue.high = queue.high + 1
+               return 0, err
+       }
+       return queue.high, nil
+}
+
+func (queue *Queue) lowincrement() (int64, error) {
+       queue.low = queue.low + 1
+       err := queue.db.Put(lowKey, id2bytes(queue.low), nil)
+       if err != nil {
+               queue.low = queue.low - 1
+               return 0, err
+       }
+       return queue.low, nil
+}
+
+func (queue *Queue) lowdecrement() (int64, error) {
+       queue.low = queue.low - 1
+       err := queue.db.Put(lowKey, id2bytes(queue.low), nil)
+       if err != nil {
+               queue.low = queue.low + 1
+               return 0, err
+       }
+       return queue.low, nil
+}
+
+// Len returns the length of the queue
+func (queue *Queue) Len() int64 {
+       queue.lowLock.Lock()
+       queue.highLock.Lock()
+       l := queue.high - queue.low + 1
+       queue.highLock.Unlock()
+       queue.lowLock.Unlock()
+       return l
+}
+
+func id2bytes(id int64) []byte {
+       var buf = make([]byte, 8)
+       binary.PutVarint(buf, id)
+       return buf
+}
+
+func bytes2id(b []byte) (int64, error) {
+       return binary.ReadVarint(bytes.NewReader(b))
+}
+
+// RPush pushes a data from right of queue
+func (queue *Queue) RPush(data []byte) error {
+       queue.highLock.Lock()
+       id, err := queue.highincrement()
+       if err != nil {
+               queue.highLock.Unlock()
+               return err
+       }
+       err = queue.db.Put(id2bytes(id), data, nil)
+       queue.highLock.Unlock()
+       return err
+}
+
+// LPush pushes a data from left of queue
+func (queue *Queue) LPush(data []byte) error {
+       queue.lowLock.Lock()
+       id, err := queue.lowdecrement()
+       if err != nil {
+               queue.lowLock.Unlock()
+               return err
+       }
+       err = queue.db.Put(id2bytes(id), data, nil)
+       queue.lowLock.Unlock()
+       return err
+}
+
+// RPop pop a data from right of queue
+func (queue *Queue) RPop() ([]byte, error) {
+       queue.highLock.Lock()
+       defer queue.highLock.Unlock()
+       currentID := queue.high
+
+       res, err := queue.db.Get(id2bytes(currentID), nil)
+       if err != nil {
+               if err == leveldb.ErrNotFound {
+                       return nil, ErrNotFound
+               }
+               return nil, err
+       }
+
+       _, err = queue.highdecrement()
+       if err != nil {
+               return nil, err
+       }
+
+       err = queue.db.Delete(id2bytes(currentID), nil)
+       if err != nil {
+               return nil, err
+       }
+       return res, nil
+}
+
+// RHandle receives a user callback function to handle the right element of the queue, if function return nil, then delete the element, otherwise keep the element.
+func (queue *Queue) RHandle(h func([]byte) error) error {
+       queue.highLock.Lock()
+       defer queue.highLock.Unlock()
+       currentID := queue.high
+
+       res, err := queue.db.Get(id2bytes(currentID), nil)
+       if err != nil {
+               if err == leveldb.ErrNotFound {
+                       return ErrNotFound
+               }
+               return err
+       }
+
+       if err = h(res); err != nil {
+               return err
+       }
+
+       _, err = queue.highdecrement()
+       if err != nil {
+               return err
+       }
+
+       return queue.db.Delete(id2bytes(currentID), nil)
+}
+
+// LPop pop a data from left of queue
+func (queue *Queue) LPop() ([]byte, error) {
+       queue.lowLock.Lock()
+       defer queue.lowLock.Unlock()
+       currentID := queue.low
+
+       res, err := queue.db.Get(id2bytes(currentID), nil)
+       if err != nil {
+               if err == leveldb.ErrNotFound {
+                       return nil, ErrNotFound
+               }
+               return nil, err
+       }
+
+       _, err = queue.lowincrement()
+       if err != nil {
+               return nil, err
+       }
+
+       err = queue.db.Delete(id2bytes(currentID), nil)
+       if err != nil {
+               return nil, err
+       }
+       return res, nil
+}
+
+// LHandle receives a user callback function to handle the left element of the queue, if function return nil, then delete the element, otherwise keep the element.
+func (queue *Queue) LHandle(h func([]byte) error) error {
+       queue.lowLock.Lock()
+       defer queue.lowLock.Unlock()
+       currentID := queue.low
+
+       res, err := queue.db.Get(id2bytes(currentID), nil)
+       if err != nil {
+               if err == leveldb.ErrNotFound {
+                       return ErrNotFound
+               }
+               return err
+       }
+
+       if err = h(res); err != nil {
+               return err
+       }
+
+       _, err = queue.lowincrement()
+       if err != nil {
+               return err
+       }
+
+       return queue.db.Delete(id2bytes(currentID), nil)
+}
+
+// Close closes the queue
+func (queue *Queue) Close() error {
+       err := queue.db.Close()
+       queue.db = nil
+       return err
+}
diff --git a/vendor/github.com/lunny/levelqueue/.gitignore b/vendor/github.com/lunny/levelqueue/.gitignore
deleted file mode 100644 (file)
index 59a8bde..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-queue/
-queue_pop/
-queue_push/
\ No newline at end of file
diff --git a/vendor/github.com/lunny/levelqueue/LICENSE b/vendor/github.com/lunny/levelqueue/LICENSE
deleted file mode 100644 (file)
index 4a5a4ea..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-Copyright (c) 2019 Lunny Xiao
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
diff --git a/vendor/github.com/lunny/levelqueue/README.md b/vendor/github.com/lunny/levelqueue/README.md
deleted file mode 100644 (file)
index 3d9fc09..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-# levelqueue
-
-Level queue is a simple queue golang library base on go-leveldb.
-
-[![CircleCI](https://circleci.com/gh/lunny/levelqueue.svg?style=shield)](https://circleci.com/gh/lunny/levelqueue)
-[![codecov](https://codecov.io/gh/lunny/levelqueue/branch/master/graph/badge.svg)](https://codecov.io/gh/lunny/levelqueue)
-[![](https://goreportcard.com/badge/github.com/lunny/levelqueue)](https://goreportcard.com/report/github.com/lunny/levelqueue) 
-
-## Installation
-
-```
-go get github.com/lunny/levelqueue
-```
-
-## Usage
-
-```Go
-queue, err := levelqueue.Open("./queue")
-
-err = queue.RPush([]byte("test"))
-
-data, err = queue.LPop()
-```
\ No newline at end of file
diff --git a/vendor/github.com/lunny/levelqueue/error.go b/vendor/github.com/lunny/levelqueue/error.go
deleted file mode 100644 (file)
index d639c5d..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2019 Lunny Xiao. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package levelqueue
-
-import "errors"
-
-var (
-       // ErrNotFound means no element in queue
-       ErrNotFound = errors.New("no key found")
-)
diff --git a/vendor/github.com/lunny/levelqueue/go.mod b/vendor/github.com/lunny/levelqueue/go.mod
deleted file mode 100644 (file)
index 7d060fc..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-module github.com/lunny/levelqueue
-
-require github.com/syndtr/goleveldb v0.0.0-20190203031304-2f17a3356c66
diff --git a/vendor/github.com/lunny/levelqueue/go.sum b/vendor/github.com/lunny/levelqueue/go.sum
deleted file mode 100644 (file)
index 5936aa8..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
-github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
-github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
-github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
-github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
-github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
-github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
-github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
-github.com/syndtr/goleveldb v0.0.0-20190203031304-2f17a3356c66 h1:AwmkkZT+TucFotNCL+aNJ/0KCMsRtlXN9fs8uoOMSRk=
-github.com/syndtr/goleveldb v0.0.0-20190203031304-2f17a3356c66/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
-golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
-gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
-gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/vendor/github.com/lunny/levelqueue/queue.go b/vendor/github.com/lunny/levelqueue/queue.go
deleted file mode 100644 (file)
index 0b2bef6..0000000
+++ /dev/null
@@ -1,214 +0,0 @@
-// Copyright 2019 Lunny Xiao. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package levelqueue
-
-import (
-       "bytes"
-       "encoding/binary"
-       "sync"
-
-       "github.com/syndtr/goleveldb/leveldb"
-)
-
-// Queue defines a queue struct
-type Queue struct {
-       db       *leveldb.DB
-       highLock sync.Mutex
-       lowLock  sync.Mutex
-       low      int64
-       high     int64
-}
-
-// Open opens a queue object or create it if not exist
-func Open(dataDir string) (*Queue, error) {
-       db, err := leveldb.OpenFile(dataDir, nil)
-       if err != nil {
-               return nil, err
-       }
-
-       var queue = &Queue{
-               db: db,
-       }
-       queue.low, err = queue.readID(lowKey)
-       if err == leveldb.ErrNotFound {
-               queue.low = 1
-               err = db.Put(lowKey, id2bytes(1), nil)
-       }
-       if err != nil {
-               return nil, err
-       }
-
-       queue.high, err = queue.readID(highKey)
-       if err == leveldb.ErrNotFound {
-               err = db.Put(highKey, id2bytes(0), nil)
-       }
-       if err != nil {
-               return nil, err
-       }
-
-       return queue, nil
-}
-
-func (queue *Queue) readID(key []byte) (int64, error) {
-       bs, err := queue.db.Get(key, nil)
-       if err != nil {
-               return 0, err
-       }
-       return bytes2id(bs)
-}
-
-var (
-       lowKey  = []byte("low")
-       highKey = []byte("high")
-)
-
-func (queue *Queue) highincrement() (int64, error) {
-       id := queue.high + 1
-       queue.high = id
-       err := queue.db.Put(highKey, id2bytes(queue.high), nil)
-       if err != nil {
-               queue.high = queue.high - 1
-               return 0, err
-       }
-       return id, nil
-}
-
-func (queue *Queue) highdecrement() (int64, error) {
-       queue.high = queue.high - 1
-       err := queue.db.Put(highKey, id2bytes(queue.high), nil)
-       if err != nil {
-               queue.high = queue.high + 1
-               return 0, err
-       }
-       return queue.high, nil
-}
-
-func (queue *Queue) lowincrement() (int64, error) {
-       queue.low = queue.low + 1
-       err := queue.db.Put(lowKey, id2bytes(queue.low), nil)
-       if err != nil {
-               queue.low = queue.low - 1
-               return 0, err
-       }
-       return queue.low, nil
-}
-
-func (queue *Queue) lowdecrement() (int64, error) {
-       queue.low = queue.low - 1
-       err := queue.db.Put(lowKey, id2bytes(queue.low), nil)
-       if err != nil {
-               queue.low = queue.low + 1
-               return 0, err
-       }
-       return queue.low, nil
-}
-
-// Len returns the length of the queue
-func (queue *Queue) Len() int64 {
-       queue.lowLock.Lock()
-       queue.highLock.Lock()
-       l := queue.high - queue.low + 1
-       queue.highLock.Unlock()
-       queue.lowLock.Unlock()
-       return l
-}
-
-func id2bytes(id int64) []byte {
-       var buf = make([]byte, 8)
-       binary.PutVarint(buf, id)
-       return buf
-}
-
-func bytes2id(b []byte) (int64, error) {
-       return binary.ReadVarint(bytes.NewReader(b))
-}
-
-// RPush pushes a data from right of queue
-func (queue *Queue) RPush(data []byte) error {
-       queue.highLock.Lock()
-       id, err := queue.highincrement()
-       if err != nil {
-               queue.highLock.Unlock()
-               return err
-       }
-       err = queue.db.Put(id2bytes(id), data, nil)
-       queue.highLock.Unlock()
-       return err
-}
-
-// LPush pushes a data from left of queue
-func (queue *Queue) LPush(data []byte) error {
-       queue.highLock.Lock()
-       id, err := queue.lowdecrement()
-       if err != nil {
-               queue.highLock.Unlock()
-               return err
-       }
-       err = queue.db.Put(id2bytes(id), data, nil)
-       queue.highLock.Unlock()
-       return err
-}
-
-// RPop pop a data from right of queue
-func (queue *Queue) RPop() ([]byte, error) {
-       queue.highLock.Lock()
-       currentID := queue.high
-
-       res, err := queue.db.Get(id2bytes(currentID), nil)
-       if err != nil {
-               queue.highLock.Unlock()
-               if err == leveldb.ErrNotFound {
-                       return nil, ErrNotFound
-               }
-               return nil, err
-       }
-
-       _, err = queue.highdecrement()
-       if err != nil {
-               queue.highLock.Unlock()
-               return nil, err
-       }
-
-       err = queue.db.Delete(id2bytes(currentID), nil)
-       queue.highLock.Unlock()
-       if err != nil {
-               return nil, err
-       }
-       return res, nil
-}
-
-// LPop pop a data from left of queue
-func (queue *Queue) LPop() ([]byte, error) {
-       queue.lowLock.Lock()
-       currentID := queue.low
-
-       res, err := queue.db.Get(id2bytes(currentID), nil)
-       if err != nil {
-               queue.lowLock.Unlock()
-               if err == leveldb.ErrNotFound {
-                       return nil, ErrNotFound
-               }
-               return nil, err
-       }
-
-       _, err = queue.lowincrement()
-       if err != nil {
-               return nil, err
-       }
-
-       err = queue.db.Delete(id2bytes(currentID), nil)
-       queue.lowLock.Unlock()
-       if err != nil {
-               return nil, err
-       }
-       return res, nil
-}
-
-// Close closes the queue
-func (queue *Queue) Close() error {
-       err := queue.db.Close()
-       queue.db = nil
-       return err
-}
index 357dfa39c4d07136a5fb314aba33f4ae224bbdc9..7673c5f172fba7298b04f896f31c2ec015b7eef8 100644 (file)
@@ -1,5 +1,7 @@
 # cloud.google.com/go v0.45.0
 cloud.google.com/go/compute/metadata
+# gitea.com/lunny/levelqueue v0.1.0
+gitea.com/lunny/levelqueue
 # gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b
 gitea.com/macaron/binding
 # gitea.com/macaron/cache v0.0.0-20190822004001-a6e7fee4ee76
@@ -277,8 +279,6 @@ github.com/lib/pq/oid
 github.com/lib/pq/scram
 # github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96
 github.com/lunny/dingtalk_webhook
-# github.com/lunny/levelqueue v0.0.0-20190217115915-02b525a4418e
-github.com/lunny/levelqueue
 # github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de
 github.com/lunny/log
 # github.com/lunny/nodb v0.0.0-20160621015157-fc1ef06ad4af