runner

package
v0.0.0-...-482fd9e Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2019 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IntervalEventType int = iota
	DataEventType
	UserEventType
)

Types of Events that exist in system

Variables

This section is empty.

Functions

This section is empty.

Types

type DataEvent

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

DataEvent occurs when new data comes from push service

func (*DataEvent) Data

func (d *DataEvent) Data() string

Data returns data associated with event

func (*DataEvent) Env

func (d *DataEvent) Env(key string) string

Env returns value of given key

func (*DataEvent) Type

func (d *DataEvent) Type() int

Type returns type of event

type Event

type Event interface {
	Type() int
	Data() string
	Env(key string) string
}

Event represents type and data of occurred events

type IntervalEvent

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

IntervalEvent occurs when user specific interval finishes

func (*IntervalEvent) Data

func (i *IntervalEvent) Data() string

Data returns data associated with event

func (*IntervalEvent) Env

func (i *IntervalEvent) Env(key string) string

Env returns value of given key

func (*IntervalEvent) Type

func (i *IntervalEvent) Type() int

Type returns type of event

type Runner

type Runner struct {
	ErrHandler func(error)
	// contains filtered or unexported fields
}

Runner runs your task on sepecific events and stores outputs. ErrHandler calls on each run that have error in another thread so write it in async mode.

func New

func New(t *Task, backlog int) *Runner

New creates new runner based on given task

func NewWithoutOutput

func NewWithoutOutput(t *Task, backlog int) *Runner

NewWithoutOutput creates new runner without any output channel

func (*Runner) DataEvent

func (r *Runner) DataEvent(ctx context.Context, data string, envs ...map[string]string) error

DataEvent push data event (string + environments) into runner events

func (*Runner) Event

func (r *Runner) Event(ctx context.Context, e Event) error

Event push event into runner events

func (*Runner) Output

func (r *Runner) Output(ctx context.Context) (string, error)

Output returns last output from output queue

func (*Runner) Start

func (r *Runner) Start()

Start starts runner and it must be call in new goroutine you can start many routine by call this function many times

func (*Runner) Status

func (r *Runner) Status() bool

Status returns true when runner is in the running state otherwise false

func (*Runner) Stop

func (r *Runner) Stop()

Stop stops runner and you cann't run it again

func (*Runner) Trigger

func (r *Runner) Trigger() Event

Trigger runner and gets its last event it blocks until one event come

type Task

type Task struct {
	Run      func(ev Event) (string, error)
	Interval time.Duration
}

Task represents single task must run on the runner Run function is called on every event

Jump to

Keyboard shortcuts

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