Documentation
¶
Overview ¶
Package synapsys connects ordinary Go business functions to Synapsys Core.
The package is framework-neutral. A Worker reports registered processes to Core, applies token-gated start and stop commands, and optionally forwards process-scoped logs. Synapsys does not schedule functions: an Endless process keeps itself alive until it observes cancellation, while a Progressive process runs once and returns naturally.
Index ¶
- type ConfigError
- type LogSource
- type Option
- func WithConnectTimeout(value time.Duration) Option
- func WithConsoleCapture(value bool) Option
- func WithCoreToken(value string) Option
- func WithCoreURL(value string) Option
- func WithEnabled(enabled bool) Option
- func WithFailFast(value bool) Option
- func WithHeartbeatInterval(value time.Duration) Option
- func WithHost(value string) Option
- func WithLogger(value *slog.Logger) Option
- func WithRequestTimeout(value time.Duration) Option
- func WithWorkerName(value string) Option
- type Process
- func Endless(name string, run func() error, options ...ProcessOption) Process
- func EndlessContext(name string, run func(context.Context) error, options ...ProcessOption) Process
- func Progressive(name string, run func() error, options ...ProcessOption) Process
- func ProgressiveContext(name string, run func(context.Context) error, options ...ProcessOption) Process
- type ProcessOption
- type ProcessState
- type ProcessStatus
- type ProcessType
- type Settings
- type StartupError
- type Worker
- func (w *Worker) Logger(processName string) *slog.Logger
- func (w *Worker) Processes() []ProcessStatus
- func (w *Worker) Register(declarations ...Process) error
- func (w *Worker) Settings() Settings
- func (w *Worker) Start() error
- func (w *Worker) Stop(ctx context.Context) error
- func (w *Worker) Writer(processName string, source LogSource, next io.Writer) io.Writer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigError ¶
type ConfigError struct{ Message string }
ConfigError reports invalid SDK configuration or process declarations.
func (*ConfigError) Error ¶
func (e *ConfigError) Error() string
type LogSource ¶
type LogSource string
LogSource identifies the conventional stream represented by a captured line.
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option configures a Worker. Options override environment variables.
func WithConnectTimeout ¶
WithConnectTimeout bounds TCP connection establishment.
func WithConsoleCapture ¶
WithConsoleCapture enables or disables explicit process Logger and Writer capture. Go does not replace the process-global os.Stdout or os.Stderr streams.
func WithCoreToken ¶
WithCoreToken sets the bearer token. Environment-based secrets are preferred.
func WithCoreURL ¶
WithCoreURL sets the Synapsys Core base URL.
func WithEnabled ¶
WithEnabled completely disables or enables Synapsys integration.
func WithFailFast ¶
WithFailFast makes an unreachable Core fail Worker.Start.
func WithHeartbeatInterval ¶
WithHeartbeatInterval sets the positive whole-second heartbeat interval.
func WithLogger ¶
WithLogger supplies the application's slog logger for SDK diagnostics and process-scoped logger passthrough.
func WithRequestTimeout ¶
WithRequestTimeout bounds a complete Core request.
func WithWorkerName ¶
WithWorkerName sets the stable identity reported across restarts.
type Process ¶
type Process struct {
// contains filtered or unexported fields
}
Process is a declaration registered with a Worker. Its fields are intentionally private so invalid combinations cannot be built without using Endless, EndlessContext, Progressive, or ProgressiveContext.
func Endless ¶
func Endless(name string, run func() error, options ...ProcessOption) Process
Endless declares long-lived logic with its own stop mechanism.
func EndlessContext ¶
EndlessContext declares long-lived logic that observes cooperative cancellation.
func Progressive ¶
func Progressive(name string, run func() error, options ...ProcessOption) Process
Progressive declares finite work that does not require in-flight cancellation.
func ProgressiveContext ¶
func ProgressiveContext(name string, run func(context.Context) error, options ...ProcessOption) Process
ProgressiveContext declares finite work that observes cooperative cancellation.
type ProcessOption ¶
type ProcessOption struct {
// contains filtered or unexported fields
}
ProcessOption configures one process declaration.
func WithOnStop ¶
func WithOnStop(hook func() error) ProcessOption
WithOnStop installs an optional cleanup hook. Endless hooks run as soon as a stop is accepted so they can unblock legacy listeners. Progressive hooks run after the body returns from a requested stop.
type ProcessState ¶
type ProcessState string
ProcessState is the state reported to Synapsys Core.
const ( StateIdle ProcessState = "idle" StateRunning ProcessState = "running" StateStopping ProcessState = "stopping" StateFailed ProcessState = "failed" )
type ProcessStatus ¶
type ProcessStatus struct {
Name string
Type ProcessType
State ProcessState
AckToken int64
RunID *int64
}
ProcessStatus is a concurrency-safe snapshot of one registered process.
type ProcessType ¶
type ProcessType string
ProcessType identifies a managed process's execution model.
const ( // TypeEndless identifies business logic that remains running until stopped. TypeEndless ProcessType = "endless" // TypeProgressive identifies finite business logic that returns naturally. TypeProgressive ProcessType = "progressive" )
type Settings ¶
type Settings struct {
Enabled bool
CoreURL string
WorkerName string
Host string
HeartbeatInterval time.Duration
FailFast bool
ConnectTimeout time.Duration
RequestTimeout time.Duration
CaptureConsole bool
}
Settings is the resolved, non-secret worker configuration.
type StartupError ¶
type StartupError struct{ Cause error }
StartupError reports a fail-fast startup failure.
func (*StartupError) Error ¶
func (e *StartupError) Error() string
func (*StartupError) Unwrap ¶
func (e *StartupError) Unwrap() error
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker owns an explicit set of Synapsys processes and their lifecycle. A Worker is safe for concurrent observation and logging.
func New ¶
New constructs a framework-neutral worker. Environment variables are resolved before options, so explicit options win. Network access begins only at Start.
func (*Worker) Logger ¶
Logger returns a process-scoped structured logger. Records continue to the application's configured logger and, while that process has an active run, are also queued for Core.
func (*Worker) Processes ¶
func (w *Worker) Processes() []ProcessStatus
Processes returns process snapshots in registration order.
func (*Worker) Register ¶
Register adds process declarations atomically. Every process must be registered before Start, and names must be unique within the worker.
Example ¶
package main
import (
"context"
"fmt"
"github.com/basamento/synapsys-go-sdk"
)
func main() {
worker, err := synapsys.New(synapsys.WithEnabled(false))
if err != nil {
panic(err)
}
err = worker.Register(
synapsys.EndlessContext("listener", func(ctx context.Context) error {
<-ctx.Done()
return ctx.Err()
}),
synapsys.Progressive("report", func() error { return nil }),
)
if err != nil {
panic(err)
}
for _, process := range worker.Processes() {
fmt.Println(process.Name, process.Type, process.State)
}
}
Output: listener endless idle report progressive idle
func (*Worker) Start ¶
Start validates configuration, performs one bounded health probe, and starts the heartbeat loop. Core unavailability is non-fatal unless fail-fast is set.
func (*Worker) Stop ¶
Stop cooperatively stops processes, waits up to ctx's deadline, sends one best-effort final state/log heartbeat, and releases transport resources. It is idempotent; final-heartbeat failures are logged and never returned.
Example ¶
package main
import (
"context"
"time"
"github.com/basamento/synapsys-go-sdk"
)
func main() {
worker, err := synapsys.New(synapsys.WithEnabled(false))
if err != nil {
panic(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_ = worker.Stop(ctx)
}
Output: