-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpkg.go
40 lines (34 loc) · 929 Bytes
/
pkg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package pqueue
import (
"io"
"github.com/linxGnu/pqueue/common"
"github.com/linxGnu/pqueue/entry"
)
const (
// DefaultMaxEntriesPerSegment is default value for max entries per segment.
DefaultMaxEntriesPerSegment = 1000
)
// QueueSettings are settings for queue.
type QueueSettings struct {
DataDir string
SegmentFormat common.SegmentFormat
EntryFormat common.EntryFormat
MaxEntriesPerSegment uint32
}
// Queue interface.
type Queue interface {
io.Closer
Enqueue(entry.Entry) error
EnqueueBatch(entry.Batch) error
Dequeue(*entry.Entry) bool
Peek(*entry.Entry) bool
}
// New queue from directory.
func New(dataDir string, maxEntriesPerSegment uint32) (Queue, error) {
return load(QueueSettings{
DataDir: dataDir,
MaxEntriesPerSegment: maxEntriesPerSegment,
SegmentFormat: common.SegmentV1,
EntryFormat: common.EntryV1,
}, &segmentHeader{})
}