Documentation ¶
Overview ¶
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
Example ¶
package main import ( "context" "fmt" "io" "log" "sync" "time" oversight "cirello.io/oversight/easy" ) func main() { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() var wg sync.WaitGroup ctx = oversight.WithContext(ctx, oversight.WithLogger(log.New(io.Discard, "", 0))) wg.Add(1) serviceName, err := oversight.Add(ctx, func(ctx context.Context) error { select { case <-ctx.Done(): return nil default: defer wg.Done() fmt.Println("executed successfully") cancel() return nil } }, oversight.RestartWith(oversight.Temporary())) if err != nil { log.Fatal(err) } wg.Wait() if err := oversight.Delete(ctx, serviceName); err != nil { log.Fatal(err) } }
Output: executed successfully
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Add ¶
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 ¶
Delete stops and removes the given service from the attached tree. If the context is not correctly prepared, it returns an ErrNoTreeAttached error
Types ¶
type Logger ¶
Logger defines the interface for any logging facility to be compatible with oversight trees.
type Option ¶
type Option func(*oversight.ChildProcessSpecification)
Option reconfigures the attachment of a process to the context tree.
type TreeOption ¶
type TreeOption = oversight.TreeOption
TreeOption are applied to change the behavior of a Tree.
func WithLogger ¶
func WithLogger(logger Logger) TreeOption
WithLogger attaches a log function to the oversight tree.