easy: cirello.io/oversight/easy Index | Examples | Files

package easy

import "cirello.io/oversight/easy"

Package easy is an easier interface to use cirello.io/oversight. Its lifecycle is managed through context.Context. Stop a given oversight tree by cancelling its context.

package main

import oversight "cirello.io/oversight/easy"

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	// use cancel() to stop the oversight
	ctx = oversight.WithContext(ctx)
	oversight.Add(ctx, func(ctx context.Context) error {
		// ...

This package is covered by this SLA: https://cirello.io/sla


ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
var wg sync.WaitGroup
ctx = oversight.WithContext(ctx, oversight.WithLogger(log.New(ioutil.Discard, "", 0)))
serviceName, err := oversight.Add(ctx, func(ctx context.Context) error {
    select {
    case <-ctx.Done():
        return nil
        defer wg.Done()
        fmt.Println("executed successfully")
        return nil
}, oversight.RestartWith(oversight.Temporary()))
if err != nil {
if err := oversight.Delete(ctx, serviceName); err != nil {


executed successfully



Package Files



var (
    // Permanent services are always restarted.
    Permanent = oversight.Permanent

    // Transient services are restarted only when panic.
    Transient = oversight.Transient

    // Temporary services are never restarted.
    Temporary = oversight.Temporary
var (
    // ErrNoTreeAttached means that the given context has not been wrapped
    // with WithContext, and thus this package cannot detect which oversight
    // tree you are referring to.
    ErrNoTreeAttached = errors.New("no oversight tree attached to context")

func Add Uses

func Add(ctx context.Context, f oversight.ChildProcess, opts ...Option) (string, error)

Add inserts a supervised function to the attached tree, it launches automatically. If the context is not correctly prepared, it returns an ErrNoTreeAttached error. The restart policy is Permanent.

func Delete Uses

func Delete(ctx context.Context, name string) error

Delete stops and removes the given service from the attached tree. If the context is not correctly prepared, it returns an ErrNoTreeAttached error

func WithContext Uses

func WithContext(ctx context.Context, opts ...TreeOption) context.Context

WithContext takes a context and prepare it to be used by easy oversight tree package. Internally, it creates an oversight tree in OneForAll mode.

type Logger Uses

type Logger = oversight.Logger

Logger defines the interface for any logging facility to be compatible with oversight trees.

type Option Uses

type Option func(*oversight.ChildProcessSpecification)

Option reconfigures the attachment of a process to the context tree.

func RestartWith Uses

func RestartWith(restart oversight.Restart) Option

RestartWith changes the restart policy for the process.

type TreeOption Uses

type TreeOption = oversight.TreeOption

TreeOption are applied to change the behavior of a Tree.

func WithLogger Uses

func WithLogger(logger Logger) TreeOption

WithLogger attaches a log function to the oversight tree.

Package easy imports 6 packages (graph) and is imported by 1 packages. Updated 2019-03-13. Refresh now. Tools for package owners.