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 ¶
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") )
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
func WithContext ¶
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.
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.
func RestartWith ¶
RestartWith changes the restart policy for the process.
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.