queue

package
Version: v0.0.0-...-dbea759 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package queue defines tasks to be performed to grow a tree as well as an interface for a Queue to manage them.

It also provides an in-memory implementation of the Queue interface

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WaitFor

func WaitFor(ctx context.Context, q Queue) error

WaitFor takes a context and a queue and waits for all its tasks to have been processed, that is, for for the given queue's Count method to return 0, 0, nil. It will return a non-nil error if the given context times out or is cancelled, or if the queue's Count operation returns an error. Use this function to wait for the processing of a tree once you have started to grow it and have workers processing its tasks.

Types

type Queue

type Queue interface {
	// Push takes a task and stores it in the queue or
	// returns an error. The task will count as pending.
	Push(context.Context, *Task) error
	// Pull returns a task and a context that may have
	// a timeout or allow its cancellation, or an error.
	// The pulled task will be counted as running from
	// then on.
	// If there are no tasks to pull, implementations
	// should not return an error, but 3 nil values.
	// In case of cancellation, workers should still
	// drop the task.
	Pull(context.Context) (*Task, context.Context, error)
	// Drop takes the ID for a tasks an makes it available
	// for pulling from the Queue again. The dropped task
	// should be count by implementations as pending
	// again, unless it has been previously completed.
	// Workers should use this to return to the queue
	// tasks they have not completed.
	Drop(context.Context, string) error
	// Complete takes the ID for a task. Implementations
	// should remove the task from the running state.
	Complete(context.Context, string) error
	// Count returns the number of
	// pending and running tasks in the queue
	// or an error
	Count(context.Context) (int, int, error)
	// Stops the queue. Implementations should use the
	// call to free resources and even cancel pulled
	// contexts.
	Stop(context.Context) error
}

Queue represents a queue where tasks to develop tree nodes can be pushed and pulled. The idea is a worker will use the Pull method to obtain a task. It will start processing it and will then either complete it or drop it halfway.

All its methods have a context.Context as first parameter that implementations may use to allow timeouts and cancellations on the Queue operations.

func New

func New() Queue

New returns a queue backed only by the process memory

type Task

type Task struct {
	// The node to be developed
	Node *tree.Node
	// The set of training data with samples
	// satisfying the constraints on the node
	// and its ancestors.
	Set set.Set
	// The list of features that can be used
	// to split the node into branches.
	// It should exclude the features used in
	// ancestor nodes.
	AvailableFeatures []feature.Feature
}

Task represents a tree.Node to be developed on a tree.Tree.

func (*Task) ID

func (t *Task) ID() string

ID returns a string that identifies the task, the ID of its Node.

func (*Task) String

func (t *Task) String() string

Jump to

Keyboard shortcuts

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