status

package
v2.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InProgressStatus = "in progress"
	SuccessStatus    = "success"
	CancelStatus     = "cancel"
	ErrorStatus      = "error"
)
View Source
const DefaultCallbackTimeout = 5 * time.Second

DefaultCallbackTimeout is used when CallbackConfig.Timeout is not positive.

View Source
const DefaultMaxFinishedRows = 1000

DefaultMaxFinishedRows is used until SetMaxFinishedRows is called from a loaded config, so a status list created before any config is read is still bounded.

View Source
const NotFromAPI = int(-1)

Variables

View Source
var CancelWaitTimeout = 1800 * time.Second

CancelWaitTimeout bounds how long Cancel/CancelAll wait for the command goroutine to return. After the timeout we give up and let the caller proceed (a stuck goroutine should not block /backup/kill forever). The default matches APIConfig.CancelOperationTimeout (1800s); the server overrides it from config on Restart/ReloadConfig.

View Source
var Current = &AsyncStatus{}

Functions

func APIServerMode added in v2.8.1

func APIServerMode() bool

APIServerMode reports whether this process runs the API server.

func CallbackEligible added in v2.8.1

func CallbackEligible(fullCommand string) bool

CallbackEligible reports whether a full command line ("create_remote --tables=x name") belongs to a command which produces a completion callback. Only the first token matters.

func ResetAPIServerModeForTest added in v2.8.1

func ResetAPIServerModeForTest()

ResetAPIServerModeForTest clears the API server marker. Tests only.

func RootContext added in v2.8.1

func RootContext() context.Context

RootContext returns the context canceled when the process is asked to terminate

func SendCallback added in v2.8.1

func SendCallback(ctx context.Context, callbackURL string, payload CallbackPayload) error

SendCallback POSTs payload as JSON to callbackURL. The caller owns timeouts via ctx.

func SetAPIServerMode added in v2.8.1

func SetAPIServerMode()

SetAPIServerMode marks this process as an API server. Never reset.

func SetCancelWaitTimeout added in v2.7.0

func SetCancelWaitTimeout(d time.Duration)

SetCancelWaitTimeout updates the global CancelWaitTimeout. Safe to call from the API server when reloading config.

func SetMaxFinishedRows added in v2.8.1

func SetMaxFinishedRows(n int)

SetMaxFinishedRows applies general.status_history_size. Safe to call from the API server on config reload, and from `watch` before its first iteration. Non-positive values are ignored, ValidateConfig already rejects them.

func SetRootContext added in v2.8.1

func SetRootContext(ctx context.Context)

SetRootContext sets the parent context of NotFromAPI commands, call it once before the CLI runs

Types

type ActionRow

type ActionRow struct {
	ActionRowStatus

	Ctx    context.Context
	Cancel context.CancelFunc
	// Done is closed by Stop when the command goroutine has fully returned.
	// Cancel/CancelAll wait on this so callers know the operation really
	// finished (e.g. defers like pidlock.RemovePidFile have already run).
	Done chan struct{}
	// contains filtered or unexported fields
}

type ActionRowStatus

type ActionRowStatus struct {
	Command     string `json:"command"`
	Status      string `json:"status"`
	Start       string `json:"start,omitempty"`
	Finish      string `json:"finish,omitempty"`
	Error       string `json:"error,omitempty"`
	OperationId string `json:"operation_id,omitempty"`
	// Result carries a command specific JSON payload, currently the DryRunReport
	// of a `--dry-run` command, https://github.com/Altinity/clickhouse-backup/issues/1012
	Result string `json:"result,omitempty"`
}

type AsyncStatus

type AsyncStatus struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*AsyncStatus) Cancel

func (status *AsyncStatus) Cancel(command string, err error) (string, error)

func (*AsyncStatus) CancelAll

func (status *AsyncStatus) CancelAll(cancelMsg string) []string

func (*AsyncStatus) CheckCommandInProgress

func (status *AsyncStatus) CheckCommandInProgress(command string) bool

func (*AsyncStatus) GetContextWithCancel

func (status *AsyncStatus) GetContextWithCancel(commandId int) (context.Context, context.CancelFunc, error)

func (*AsyncStatus) GetStatus

func (status *AsyncStatus) GetStatus(current bool, filter string, last int) []ActionRowStatus

func (*AsyncStatus) GetStatusByOperationId added in v2.6.30

func (status *AsyncStatus) GetStatusByOperationId(operationId string) []ActionRowStatus

func (*AsyncStatus) InProgress

func (status *AsyncStatus) InProgress() bool

InProgress any .Status == InProgressStatus command shall return true, https://github.com/Altinity/clickhouse-backup/issues/827

func (*AsyncStatus) SetResult added in v2.8.1

func (status *AsyncStatus) SetResult(commandId int, result string)

SetResult attaches a command specific JSON payload to a row, so it becomes visible in /backup/status, GET /backup/actions and system.backup_actions. MUST be called before Stop, a poller which sees a finished row expects the result to be there already.

func (*AsyncStatus) Start

func (status *AsyncStatus) Start(command string) (int, context.Context)

func (*AsyncStatus) StartWithCallback added in v2.8.1

func (status *AsyncStatus) StartWithCallback(command string, operationId string, callback *CallbackConfig) (int, context.Context)

StartWithCallback registers a command and attaches the completion callback configuration to it. Passing a nil callback, an empty URL list or a command which is not CallbackEligible means no callback is sent when it finishes.

func (*AsyncStatus) StartWithOperationId added in v2.6.30

func (status *AsyncStatus) StartWithOperationId(command string, operationId string) (int, context.Context)

func (*AsyncStatus) Stop

func (status *AsyncStatus) Stop(commandId int, err error)

type CallbackConfig added in v2.8.1

type CallbackConfig struct {
	URLs    []string
	Timeout time.Duration
}

CallbackConfig describes where to notify when a command finishes. It is attached to a status row by the caller which starts the command (API handler, CLI wrapper or watch iteration).

type CallbackPayload added in v2.8.1

type CallbackPayload struct {
	Status      string `json:"status"`
	Error       string `json:"error"`
	OperationId string `json:"operation_id"`
	Command     string `json:"command,omitempty"`
	Duration    string `json:"duration,omitempty"`
}

CallbackPayload is the JSON body posted to callback URLs on command completion. Status, Error, and OperationId match the legacy API callback payload for backward compatibility (Error has no omitempty so success still sends ""). Command and Duration are optional extras.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL