Skip to content
Kingson4WuPublic

About

๐Ÿ”Œ saturn client for golang sever. ๐Ÿต

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

ย 

History

19 Commits

Folders and files

Repository files navigation

CI/CD Pipeline Go Report Card GitHub top language GitHub stars codecov Go Reference Mentioned in Awesome Go LICENSE

English | ็ฎ€ไฝ“ไธญๆ–‡ | deepwiki


Saturn CLI (Go)

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.

Documentation

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

Highlights

  • 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 --stop semantics and CTRL+C interception.
  • Structured CLI experience โ€“ Repeatable --param key=value flags, 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.

Architecture Overview

Saturn CLI design overview

Getting Started

Prerequisites

  • Go 1.19 or newer
  • Unix-like system for socket transport (Windows is supported via TCP loopback)

Build

make

This produces two binaries:

  • saturn_svr โ€“ reference server demonstrating job registration
  • saturn_cli โ€“ command-line client

Run the demo

./saturn_svr
./saturn_cli --name hello --param id=33 --param ver=22
./saturn_cli --name hello_stoppable
./saturn_cli --name hello_stoppable --stop

Use CTRL+C while a stoppable job is running to trigger an interrupt with automatic stop propagation.

Embedding in Your Service

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.

CLI Reference

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 usage

The CLI returns exit code 0 on success or interrupt, and 1 on failure.

Server API Reference

  • server.NewRegistry() โ€“ create an isolated registry
  • registry.AddJob(name, handler) โ€“ register a synchronous job
  • registry.AddStoppableJob(name, handler) โ€“ register a job that accepts a quit channel
  • server.NewServer(logger, sockPath, opts...) โ€“ construct a server bound to a socket path
  • server.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.

Testing

go test ./...

The suite includes end-to-end tests that spin up in-memory registries and verify stop semantics.

Documentation

Contributing

Contributions are welcome! Please read the CONTRIBUTING guide before opening issues or pull requests.

License

Saturn CLI is licensed under the terms of the Apache 2.0 License.

About

๐Ÿ”Œ saturn client for golang sever. ๐Ÿต

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages