Documentation
¶
Overview ¶
Package process adapts standard-library os/exec commands to sup actors.
Getting started ¶
Create a process Actor with a command factory, then place it under a sup Supervisor:
worker := process.NewActor("worker", func(ctx context.Context) *exec.Cmd {
return exec.CommandContext(ctx, "./worker", "--serve")
})
supervisor := sup.NewSupervisor("root", sup.Transient).AddActors(worker)
The command factory is called once for every execution attempt and must return a fresh *exec.Cmd. Configure environment, working directory, output, and cancellation on that command using the standard library.
Use exec.CommandContext with the supplied context when cancellation should stop the process. Context cancellation is a clean actor shutdown and makes Run return nil. Other command errors are returned to the supervisor and are handled by its restart policy.
See the package README and the package reference at https://pkg.go.dev/github.com/webermarci/sup/process for the complete API.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Actor ¶
type Actor struct {
// contains filtered or unexported fields
}
Actor creates and runs an external command for each execution attempt. Process configuration and cancellation behavior belong to the command factory; the actor only adapts the command lifecycle to sup.Actor.
Example ¶
package main
import (
"context"
"fmt"
"os"
"os/exec"
"github.com/webermarci/sup"
"github.com/webermarci/sup/process"
)
func main() {
command := process.NewActor("hello", func(ctx context.Context) *exec.Cmd {
cmd := exec.CommandContext(ctx, "sh", "-c", "printf 'hello from process actor\\n'")
cmd.Stdout = os.Stdout
return cmd
})
supervisor := sup.NewSupervisor("root", sup.Temporary).
AddActors(command)
if err := supervisor.Run(context.Background()); err != nil {
panic(err)
}
fmt.Println("process finished")
}
Output: hello from process actor process finished