queue

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package queue provides URL queue implementations for the crawler.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrQueueEmpty  = errors.New("queue is empty")
	ErrQueueClosed = errors.New("queue is closed")
)

Functions

This section is empty.

Types

type FastQueue

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

FastQueue is a high-performance queue optimized for concurrent access. It uses sharding to reduce lock contention and supports batch operations.

func NewFastQueue

func NewFastQueue(capacity int) *FastQueue

NewFastQueue creates a new high-performance queue.

func (*FastQueue) Clear

func (fq *FastQueue) Clear() error

Clear removes all items from the queue.

func (*FastQueue) Close

func (fq *FastQueue) Close() error

Close closes the queue and wakes all waiters.

func (*FastQueue) Contains

func (fq *FastQueue) Contains(url string) bool

Contains checks if a URL is in the queue.

func (*FastQueue) IsEmpty

func (fq *FastQueue) IsEmpty() bool

IsEmpty returns true if the queue is empty.

func (*FastQueue) Len

func (fq *FastQueue) Len() int

Len returns the total number of items across all shards.

func (*FastQueue) Pop

func (fq *FastQueue) Pop() (*QueueItem, error)

Pop removes and returns the next item (non-blocking).

func (*FastQueue) PopBatch

func (fq *FastQueue) PopBatch(n int) ([]*QueueItem, error)

PopBatch removes and returns up to n items.

func (*FastQueue) PopWait

func (fq *FastQueue) PopWait() (*QueueItem, error)

PopWait removes and returns the next item, blocking if empty.

func (*FastQueue) Push

func (fq *FastQueue) Push(item *QueueItem) error

Push adds an item to the queue.

func (*FastQueue) PushBatch

func (fq *FastQueue) PushBatch(items []*QueueItem) (int, error)

PushBatch adds multiple items to the queue efficiently.

func (*FastQueue) Stats

func (fq *FastQueue) Stats() QueueStats

func (*FastQueue) URLs

func (fq *FastQueue) URLs() []string

URLs returns all URLs currently in the queue.

type MemoryQueue

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

MemoryQueue is a thread-safe in-memory priority queue.

func NewMemoryQueue

func NewMemoryQueue(capacity int) *MemoryQueue

NewMemoryQueue creates a new in-memory queue.

func (*MemoryQueue) Clear

func (mq *MemoryQueue) Clear() error

Clear removes all items from the queue.

func (*MemoryQueue) Close

func (mq *MemoryQueue) Close() error

Close closes the queue.

func (*MemoryQueue) Contains

func (mq *MemoryQueue) Contains(url string) bool

Contains checks if a URL is in the queue.

func (*MemoryQueue) IsEmpty

func (mq *MemoryQueue) IsEmpty() bool

IsEmpty returns true if the queue is empty.

func (*MemoryQueue) Len

func (mq *MemoryQueue) Len() int

Len returns the number of items in the queue.

func (*MemoryQueue) Peek

func (mq *MemoryQueue) Peek() (*QueueItem, error)

Peek returns the next item without removing it.

func (*MemoryQueue) Pop

func (mq *MemoryQueue) Pop() (*QueueItem, error)

Pop removes and returns the next item from the queue.

func (*MemoryQueue) PopWait

func (mq *MemoryQueue) PopWait() (*QueueItem, error)

PopWait removes and returns the next item, blocking if empty.

func (*MemoryQueue) Push

func (mq *MemoryQueue) Push(item *QueueItem) error

Push adds an item to the queue.

func (*MemoryQueue) URLs

func (mq *MemoryQueue) URLs() []string

URLs returns all URLs currently in the queue.

type PersistentQueue

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

PersistentQueue is a disk-backed queue using BoltDB.

func NewPersistentQueue

func NewPersistentQueue(dbPath string, maxMemory int) (*PersistentQueue, error)

NewPersistentQueue creates a new persistent queue.

func (*PersistentQueue) Clear

func (pq *PersistentQueue) Clear() error

Clear removes all items from the queue.

func (*PersistentQueue) Close

func (pq *PersistentQueue) Close() error

Close closes the queue and database.

func (*PersistentQueue) Contains

func (pq *PersistentQueue) Contains(url string) bool

Contains checks if a URL is in the queue or has been visited.

func (*PersistentQueue) IsEmpty

func (pq *PersistentQueue) IsEmpty() bool

IsEmpty returns true if the queue is empty.

func (*PersistentQueue) Len

func (pq *PersistentQueue) Len() int

Len returns the approximate number of items in the queue.

func (*PersistentQueue) Peek

func (pq *PersistentQueue) Peek() (*QueueItem, error)

Peek returns the next item without removing it.

func (*PersistentQueue) Pop

func (pq *PersistentQueue) Pop() (*QueueItem, error)

Pop removes and returns the next item from the queue.

func (*PersistentQueue) Push

func (pq *PersistentQueue) Push(item *QueueItem) error

Push adds an item to the queue.

func (*PersistentQueue) Stats

func (pq *PersistentQueue) Stats() (queueSize, visitedCount int)

Stats returns queue statistics.

type Queue

type Queue interface {
	// Push adds an item to the queue
	Push(item *QueueItem) error

	// Pop removes and returns the next item from the queue
	Pop() (*QueueItem, error)

	// Peek returns the next item without removing it
	Peek() (*QueueItem, error)

	// Len returns the number of items in the queue
	Len() int

	// IsEmpty returns true if the queue is empty
	IsEmpty() bool

	// Clear removes all items from the queue
	Clear() error

	// Close closes the queue and releases resources
	Close() error

	// Contains checks if a URL is already in the queue
	Contains(url string) bool
}

Queue defines the interface for URL queues.

type QueueItem

type QueueItem struct {
	URL       string
	Method    string
	Depth     int
	ParentURL string
	Headers   map[string]string
	Body      []byte
	Priority  int
	Timestamp time.Time
}

QueueItem represents an item in the crawl queue.

type QueueStats

type QueueStats struct {
	TotalItems   int
	ShardSizes   []int
	DedupEntries int
}

Stats returns queue statistics.

Jump to

Keyboard shortcuts

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