queue

package
v0.0.0-...-c5d5a31 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Overview

Package queue manages the queue for a distributed crawler

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyReserved = errors.New("host already reserved")

ErrAlreadyReserved indicates another worker reserved the host

View Source
var ErrNotQueued = errors.New("link already queued")

ErrNotQueued indicates a link was not queued

Functions

This section is empty.

Types

type Queuer

type Queuer interface {
	CountLinks() (int64, error)
	AddLink(lnk string) error
	QueueLink(ttl time.Duration) (string, error)
	ReserveHost(host string, ttl time.Duration) error
	DelayHost(host string, ttl time.Duration) error
}

Queuer is handles links and our crawling queue

type Redis

type Redis struct {
	RedisPool *redis.Pool
}

Redis implements the Queuer interface

func (r *Redis) AddLink(lnk string) error

AddLink adds a link to our redis set

func (r *Redis) CountLinks() (int64, error)

CountLinks counts the number of links in our queue

func (*Redis) DelayHost

func (r *Redis) DelayHost(host string, ttl time.Duration) error

DelayHost is like ReserveHost but makes sure the key is already set. If key doesn't exist then something is wrong (eg reservation < crawler's timeout)

func (r *Redis) QueueLink(ttl time.Duration) (string, error)

QueueLink pops a link from our set

func (*Redis) ReserveHost

func (r *Redis) ReserveHost(host string, ttl time.Duration) error

ReserveHost reserves a host for crawling

Jump to

Keyboard shortcuts

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