boltqueue

package module
v0.0.0-...-44bdeca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2021 License: MIT Imports: 6 Imported by: 0

README

boltqueueGoDoc

-- import "github.com/alaska/boltqueue"

Package boltqueue provides a persistent queue or priority queue based on boltdb (https://github.com/boltdb/bolt)

Priority Queue

boltqueue's PQueue type represents a priority queue. Messages may be inserted into the queue at a numeric priority between 0(highest) and 255(lowest). Messages are dequeued following priority order, then time ordering, with the oldest messages of the highest priority emerging first.

Usage

type Message
type Message struct {
}

Message represents a message in the priority queue

func NewMessage
func NewMessage(value string) *Message

NewMessage generates a new priority queue message

func (*Message) Priority
func (m *Message) Priority() int

Priority returns the priority the message had in the queue in the range of 0-255 or -1 if the message is new.

func (*Message) ToString
func (m *Message) ToString() string

ToString outputs the string representation of the message's value

type PQueue
type PQueue struct {
}

PQueue is a priority queue backed by a Bolt database on disk

func NewPQueue
func NewPQueue(filename string) (*PQueue, error)

NewPQueue loads or creates a new PQueue with the given filename

func (*PQueue) Close
func (b *PQueue) Close() error

Close closes the queue and releases all resources

func (*PQueue) Dequeue
func (b *PQueue) Dequeue() (*Message, error)

Dequeue removes the oldest, highest priority message from the queue and returns it

func (*PQueue) Enqueue
func (b *PQueue) Enqueue(priority int, message *Message) error

Enqueue adds a message to the queue

func (*PQueue) Requeue
func (b *PQueue) Requeue(priority int, message *Message) error

Requeue adds a message back into the queue, keeping its precedence. If added at the same priority, it should be among the first to dequeue. If added at a different priority, it will dequeue before newer messages of that priority.

func (*PQueue) Size
func (b *PQueue) Size(priority int) (int, error)

Size returns the number of entries of a given priority from 1 to 5

Documentation

Overview

Package boltqueue provides a persistent queue or priority queue based on boltdb (https://github.com/McSwitch/bolt)

Priority Queue

boltqueue's PQueue type represents a priority queue. Messages may be inserted into the queue at a numeric priority between 0(highest) and 255(lowest). Messages are dequeued following priority order, then time ordering, with the oldest messages of the highest priority emerging first.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	// contains filtered or unexported fields
}

Message represents a message in the priority queue

func NewMessage

func NewMessage(value string) *Message

NewMessage generates a new priority queue message

func (*Message) Priority

func (m *Message) Priority() int

Priority returns the priority the message had in the queue in the range of 0-255 or -1 if the message is new.

func (*Message) ToString

func (m *Message) ToString() string

ToString outputs the string representation of the message's value

type Options

type Options struct {
	// Timeout is the amount of time to wait to obtain a file lock.
	// When set to zero it will wait indefinitely. This option is only
	// available on Darwin and Linux.
	Timeout time.Duration

	// Sets the DB.NoGrowSync flag before memory mapping the file.
	NoGrowSync bool

	// Open database in read-only mode. Uses flock(..., LOCK_SH |LOCK_NB) to
	// grab a shared lock (UNIX).
	ReadOnly bool

	// Sets the DB.MmapFlags flag before memory mapping the file.
	MmapFlags int

	// InitialMmapSize is the initial mmap size of the database
	// in bytes. Read transactions won't block write transaction
	// if the InitialMmapSize is large enough to hold database mmap
	// size. (See DB.Begin for more information)
	//
	// If <=0, the initial map size is 0.
	// If initialMmapSize is smaller than the previous database size,
	// it takes no effect.
	InitialMmapSize int
}

Options represents the options that can be set when opening a database.

type PQueue

type PQueue struct {
	// contains filtered or unexported fields
}

PQueue is a priority queue backed by a Bolt database on disk

func NewPQueue

func NewPQueue(filename string, options *Options) (*PQueue, error)

NewPQueue loads or creates a new PQueue with the given filename

func (*PQueue) Close

func (b *PQueue) Close() error

Close closes the queue and releases all resources

func (*PQueue) Dequeue

func (b *PQueue) Dequeue() (*Message, error)

Dequeue removes the oldest, highest priority message from the queue and returns it

func (*PQueue) Enqueue

func (b *PQueue) Enqueue(priority int, message *Message) error

Enqueue adds a message to the queue

func (*PQueue) Requeue

func (b *PQueue) Requeue(priority int, message *Message) error

Requeue adds a message back into the queue, keeping its precedence. If added at the same priority, it should be among the first to dequeue. If added at a different priority, it will dequeue before newer messages of that priority.

func (*PQueue) Size

func (b *PQueue) Size(priority int) (int, error)

Size returns the number of entries of a given priority from 1 to 5

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL