English | ็ฎไฝไธญๆ | deepwiki
Saturn CLI is a lightweight client/server toolkit that lets you trigger and monitor shell-style jobs from your Go services or the command line. The client communicates with a long-running daemon over Unix domain sockets (macOS/Linux) or HTTP (Windows), providing a fast, secure channel for orchestrating background work such as scheduled tasks in Saturn.
This project is a Go CLI client implementation based on the Saturn distributed task scheduling system originally developed by VipShop. The Saturn CLI toolkit is designed to be embedded directly into existing services. You can register jobs programmatically, expose them via the bundled server, and control execution through the CLI or custom integrations built on top of the client package.
Complete documentation for Saturn CLI is available in the documentation directory and can be viewed online at our documentation site. The documentation includes:
- Getting started guides
- API references
- Architecture documentation
- Usage examples
- Best practices
- Embeddable job runtime โ Register regular or stoppable jobs using a composable registry that can be scoped per service instance.
- Socket-first transport โ Uses Unix domain sockets by default for low latency and predictable permissions, with automatic TCP fallback on Windows.
- Graceful cancellation โ Stoppable jobs receive a dedicated quit channel and the client exposes
--stopsemantics andCTRL+Cinterception. - Structured CLI experience โ Repeatable
--param key=valueflags, helpful diagnostics, and consistent exit codes make automation scripts straightforward. - Production-ready ergonomics โ Context-aware HTTP clients, signal cleanup, and comprehensive integration tests keep long-lived processes healthy.
- Go 1.19 or newer
- Unix-like system for socket transport (Windows is supported via TCP loopback)
makeThis produces two binaries:
saturn_svrโ reference server demonstrating job registrationsaturn_cliโ command-line client
./saturn_svr
./saturn_cli --name hello --param id=33 --param ver=22
./saturn_cli --name hello_stoppable
./saturn_cli --name hello_stoppable --stopUse CTRL+C while a stoppable job is running to trigger an interrupt with automatic stop propagation.
package main
import (
"log"
"github.com/Kingson4Wu/saturncli/server"
"github.com/Kingson4Wu/saturncli/utils"
)
func main() {
registry := server.NewRegistry()
if err := registry.AddJob("hello", func(args map[string]string, signature string) bool {
log.Printf("hello %v (run=%s)", args, signature)
return true
}); err != nil {
log.Fatal(err)
}
if err := registry.AddStoppableJob("slow-task", func(args map[string]string, signature string, quit chan struct{}) bool {
for {
select {
case <-quit:
return true
default:
// do work...
}
}
}); err != nil {
log.Fatal(err)
}
server.NewServer(&utils.DefaultLogger{}, "/tmp/saturn.sock", server.WithRegistry(registry)).Serve()
}Clients can be embedded as well:
import (
"github.com/Kingson4Wu/saturncli/client"
"github.com/Kingson4Wu/saturncli/utils"
)
cli := client.NewClient(&utils.DefaultLogger{}, "/tmp/saturn.sock")
result := cli.Run(&client.Task{
Name: "hello",
Params: map[string]string{"id": "42"},
})result will contain one of success, failure, or interrupt.
saturn_cli [FLAGS]
Flags:
--name string Job name to execute (required)
--args string Legacy query string, merged with --param values
--param key=value Repeatable structured argument
--stop Send a stop signal instead of starting a job
--signature string Target a specific run when stopping
--help Show detailed usageThe CLI returns exit code 0 on success or interrupt, and 1 on failure.
server.NewRegistry()โ create an isolated registryregistry.AddJob(name, handler)โ register a synchronous jobregistry.AddStoppableJob(name, handler)โ register a job that accepts a quit channelserver.NewServer(logger, sockPath, opts...)โ construct a server bound to a socket pathserver.WithRegistry(registry)โ inject a custom registry (defaults to a package-level shared registry)
Use client.Task.Params for structured argument passing; Task.Args is preserved for existing integrations that already supply URL query strings.
go test ./...The suite includes end-to-end tests that spin up in-memory registries and verify stop semantics.
Contributions are welcome! Please read the CONTRIBUTING guide before opening issues or pull requests.
Saturn CLI is licensed under the terms of the Apache 2.0 License.
