provider

package
v0.0.0-...-4685c53 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package provider co-ordinates tasks and events for the lifecycle of the application.

Providers

Creating an empty provider is simple using the New function. Then, tasks are created using their configurations and added to the provider.

provider := provider.New()
if task, err := provider.New(context.Background(), provider.Task{ Label: "task_instance_1" }); err != nil {
	// Handle error
} else {
	// Use task
}

Here, context is used to pass in additional values from the calling application. Once one more more tasks have been created, they can be run:

  if err := provider.Run(ctx); err != nil {
	// ...
  }

This will run all the tasks in the background, ensuring that any dependencies for tasks are satisfied when the context is cancelled.

Events

Events are used to communicate between tasks. You can subscribe to the stream of events....

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() *provider

New creates a new empty provider with no tasks

Types

type Config

type Config struct {
	Label_ string `hcl:"label,label" json:"label,omitempty"`
}

Config is the basic configuration for a task, which includes a simple label for the task

func (Config) Label

func (c Config) Label() string

Return the label of the task instance

func (Config) Name

func (c Config) Name() string

Return the unique name of the task plugin

func (Config) New

Create a task instance from a configuration

type Task

type Task struct {
	event.PubSub
}

This is the most basic task, which just emits a single event on startup, and can be used as an example of task creation and lifecycle.

func (*Task) Run

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

func (*Task) String

func (task *Task) String() string

Jump to

Keyboard shortcuts

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