boltqueue

package module
Version: v0.0.0-...-725b849 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2018 License: MIT Imports: 5 Imported by: 1

README

bboltqueueGoDoc

Documentation Build Status Report Card

import "jaytaylor.com/bboltqueue"

Package boltqueue provides a persistent queue or priority queue based on boltdb.

Based on boltqueue.

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.

Requirements

  • Go v1.7 or newer

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 NewMessageB
func NewMessageB(value []byte) *Message

NewMessageB generates a new priority queue message from a byte slice

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(db *bolt.DB) (*PQueue, error)

NewPQueue uses an already open *bolt.DB

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

NewPQueueFromFile 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(topic string) (*Message, error)

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

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

Enqueue adds a message to the queue filed under the specified topic

func (*PQueue) Scan
func (b *PQueue) Scan(topic string, fn func(m *Message)

Invokes the supplied callback function on each message for the named topic.

func (*PQueue) ScanWithBreak
func (b *PQueue) ScanWithBreak(topic string, fn func(m *Message)

Invokes the supplied callback function on each message for the named topic until the callback returns false.

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

Requeue adds a message back into the topic 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(topic string, 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/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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Key   uint64
	Value []byte
	// 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 NewMessageB

func NewMessageB(value []byte) *Message

NewMessageB generates a new priority queue message from a byte slice

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 {
	// contains filtered or unexported fields
}

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

func NewPQueue

func NewPQueue(db *bolt.DB) *PQueue

NewPQueue consumes an existing opened *bold.DB.

func NewPQueueFromFile

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

NewPQueueFromFile 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(topic string) (*Message, error)

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

func (*PQueue) Enqueue

func (b *PQueue) Enqueue(topic string, priority int, messages ...*Message) error

Enqueue adds a message to the queue

func (*PQueue) Len

func (b *PQueue) Len(topic string, priority int) (int, error)

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

func (*PQueue) Requeue

func (b *PQueue) Requeue(topic string, priority int, messages ...*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) Scan

func (b *PQueue) Scan(topic string, fn func(m *Message)) error

Scan invokes a callback on each message in a topic.

func (*PQueue) ScanWithBreak

func (b *PQueue) ScanWithBreak(topic string, fn func(m *Message) bool) error

ScanWithBreak invokes a callback on each message in a topic as long as the callback returns true.

Jump to

Keyboard shortcuts

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