consumer

package
v0.0.0-...-a1d1ef6 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2017 License: Apache-2.0 Imports: 8 Imported by: 2

README

nsq app

This library is simply a command line application that can be constructed using your own spiders. Example spider can be found in crawl repo.

Skeleton

To create your own nsq crawler you can simply copy skeleton/ directory and add your own spiders.

After copying it should be enough to replace all occurences of github.com/crackcomm/crawl/skeleton to new path of the application. If you want CircleCI to deploy docker image for you change crawl/skeleton to your image name in circle.yaml.

Command-line Usage
$ skeleton --help
NAME:
   crawler - nsq crawl consumer

USAGE:
   crawler [global options] command [command options] [arguments...]
   
VERSION:
   0.0.1
   
COMMANDS:
   help, h	Shows a list of commands or help for one command
   
GLOBAL OPTIONS:
   --topic "crawl_requests"						crawl requests nsq topic (required) [$TOPIC]
   --channel "default"							crawl requests nsq channel (required) [$CHANNEL]
   --nsq-addr [--nsq-addr option --nsq-addr option]			 [$NSQ_ADDR]
   --nsqlookup-addr [--nsqlookup-addr option --nsqlookup-addr option]	 [$NSQLOOKUP_ADDR]
   --concurrency "100"							 [$CONCURRENCY]
   --help, -h								show help
   --version, -v							print the version
   

Documentation

Overview

Package consumer implements command line crawl consumer from nsq.

Index

Constants

This section is empty.

Variables

View Source
var Flags = []cli.Flag{
	clinsq.AddrFlag,
	clinsq.LookupAddrFlag,
	clinsq.TopicFlag,
	clinsq.ChannelFlag,
	&cli.IntFlag{
		Name:    "concurrency",
		Value:   100,
		EnvVars: []string{"CONCURRENCY"},
	},
	&cli.IntFlag{
		Name:    "timeout",
		Usage:   "default timeout in seconds",
		Value:   30,
		EnvVars: []string{"TIMEOUT"},
	},
}

Flags - Consumer app flags.

Functions

func New

func New(opts ...Option) *cli.App

New - Creates nsq consumer app.

Types

type App

type App struct {
	// Ctx - Cli context, set on action.
	Ctx *cli.Context

	// Queue - NSQ queue. Constructed on first Action() call.
	*nsqcrawl.Queue
	// contains filtered or unexported fields
}

App - Consumer command line application structure.

func (*App) Action

func (app *App) Action(c *cli.Context) error

Action - Command line action.

func (*App) Before

func (app *App) Before(c *cli.Context) (err error)

Before - Executed before action.

func (*App) Crawler

func (app *App) Crawler() crawl.Crawler

Crawler - Returns app crawler. Constructs if empty.

type Option

type Option func(*App)

Option - Consumer app option setter.

func WithBefore

func WithBefore(fnc func(*App) error) Option

WithBefore - Overwrites flag checking before action.

func WithCrawler

func WithCrawler(crawler crawl.Crawler) Option

WithCrawler - Registers spider on a crawler.

func WithCrawlerConstructor

func WithCrawlerConstructor(fnc func(*App) crawl.Crawler) Option

WithCrawlerConstructor - Constructs a crawler on action.

func WithHandler

func WithHandler(name string, h crawl.Handler) Option

WithHandler - Registers crawler handler. It has to be set after WithCrawler (if any).

func WithMiddlewares

func WithMiddlewares(middlewares ...crawl.Middleware) Option

WithMiddlewares - Registers middlewares on a crawler. It has to be set after WithCrawler (if any).

func WithSpiderConstructor

func WithSpiderConstructor(fnc func(*App) Spider) Option

WithSpiderConstructor - Constructs a spider on action.

func WithSpiders

func WithSpiders(spiders ...Spider) Option

WithSpiders - Registers spider on a crawler. It has to be set after WithCrawler (if any).

type Spider

type Spider func(crawl.Crawler)

Spider - Spider registrator.

Jump to

Keyboard shortcuts

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