task

package
v1.1.16 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Overview

package `task` implements a generic task runner, which can be a source of events

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyForPlugin added in v1.1.3

func KeyForPlugin(plugin iface.Plugin) string

KeyForPlugin returns the canonical key for a plugin

func NewGraph added in v1.1.3

func NewGraph(plugins ...iface.Plugin) *graph

NewGraph creates a graph of plugins, so that dependencies can be resolved in the correct order and there are no circular references

func NewProvider

func NewProvider(parent context.Context, plugins ...iface.Plugin) (iface.Provider, error)

Register adds a plugin to the map of plugins. It will return errors if the name or label is invalid, or the plugin with the same name already exists.

func NewTask

func NewTask(ctx context.Context, provider iface.Provider) (iface.Task, error)

Create a new default task

func PluginWithPath

func PluginWithPath(path string) (iface.Plugin, error)

Create a new plugin from a filepath

Types

type Plugin

type Plugin struct {
	Name_  types.String `json:"name,omitempty"`
	Label_ types.String `json:"label,omitempty"`
}

Plugin creates tasks from a configuration

func WithLabel

func WithLabel(name, label string) Plugin

Return a new task with the given label

func (Plugin) HasNameLabel

func (p Plugin) HasNameLabel() error

Return error if the plugin does not have a name or label

func (Plugin) Label

func (p Plugin) Label() string

Return label of the plugin

func (Plugin) Name

func (p Plugin) Name() string

Return name of the plugin

func (Plugin) New

func (p Plugin) New(c context.Context, provider iface.Provider) (iface.Task, error)

Create a new default task from the plugin

func (Plugin) String

func (p Plugin) String() string

Return string representation for a plugin

func (Plugin) WithLabel

func (p Plugin) WithLabel(label string) iface.Plugin

Create a new default task from the plugin

type Plugins

type Plugins map[string]iface.Plugin

Plugins is a map of all registered plugins

func (Plugins) Array

func (p Plugins) Array() []iface.Plugin

Return plugins as an array

func (Plugins) LoadPluginsForPattern

func (p Plugins) LoadPluginsForPattern(pattern string, replace bool) error

LoadPluginsForPattern will load and return a map of plugins for a given glob pattern, keyed against the plugin name. Any plugins which already exist are replaced, if the argument is true

func (Plugins) Register

func (p Plugins) Register(v ...iface.Plugin) error

Register adds a plugin to the map of plugins. It will return errors if the name or label is invalid, or the plugin with the same name already exists.

func (Plugins) WithName added in v1.1.2

func (p Plugins) WithName(name string) []iface.Plugin

Return a plugins by name, or nil if the plugin does not exist

type Task

type Task struct {
	event.Source
}

Task is a basic task type, which provides a single long-running task until cancel is called. It can also

func (*Task) Run

func (t *Task) Run(ctx context.Context) error

Run will block the task run until the context is cancelled or deadline exceeded, and then return the reason for cancellation.

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