operation

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package operation — ожидание долгих операций облака: опрос до done, пауза между опросами, терпимость к временным сбоям и предел --timeout. Одно место для DBaaS (ClickHouse, Redis, Kafka), VPC и подсетей; тексты пользователю — в output.

Index

Constants

View Source
const MaxFailures = 5

MaxFailures — сколько временных сбоев опроса подряд терпит ожидание: 9.10 Kafka уронила 60-минутное ожидание одним `unexpected EOF`, хотя операция в облаке шла дальше.

Variables

View Source
var ErrPending = i18n.Sentinel("operation.err.pending")

ErrPending — ожидание кончилось, а операция в облаке, возможно, идёт: повтор create дал бы второй ресурс, поэтому это не обычная ошибка.

Functions

func Transient

func Transient(err error) error

Transient помечает сбой опроса как временный (сеть, 429, 5xx).

func Until

func Until(parent context.Context, what string, opts Options, done func(context.Context) (bool, error)) error

Until опрашивает done до true; what — что ждём, если это не операция (подсеть). Временный сбой (Transient) повторяется до MaxFailures раз подряд; другой сбой и конец времени — *PendingError: в облаке операция могла продолжиться. *FailedError проходит как есть.

Types

type FailedError

type FailedError struct{ Op Operation }

FailedError — операция завершилась ошибкой.

func (*FailedError) Error

func (e *FailedError) Error() string

type Getter

type Getter func(ctx context.Context, id string) (Operation, error)

Getter запрашивает операцию по id. Ошибку, после которой опрос стоит повторить, оборачивает Transient.

type Operation

type Operation struct {
	ID          string
	ResourceID  string
	Description string
	Done        bool
	// Failed — в ответе есть error, даже без message: error без message — тоже
	// ошибка, не успех.
	Failed  bool
	Message string
	// Raw — тело ответа, из которого собрана операция: --json печатает его как есть.
	Raw []byte
}

Operation — операция в общем виде: схема DBaaS и VPC сводятся к ней.

type Options

type Options struct {
	Timeout time.Duration
	// Delay — первая пауза между опросами; дальше растёт до 4×Delay.
	Delay time.Duration
	// Progress получает новое описание операции, Retry — временный сбой опроса.
	Progress func(desc string)
	Retry    func(err error)
}

Options — настройки ожидания; нулевая Delay — 5 с, nil-функции молчат.

type PendingError

type PendingError struct {
	// ID — операция, которую ждали; What — что ждали, если это не операция (подсеть).
	ID, What string
	Timeout  time.Duration
	Cause    error
}

PendingError — ожидание оборвалось: истёк Timeout, прервали снаружи (Cause — context.Canceled) или опрос не удался (Cause — его ошибка).

func (*PendingError) Error

func (e *PendingError) Error() string

func (*PendingError) Is

func (e *PendingError) Is(target error) bool

func (*PendingError) Unwrap

func (e *PendingError) Unwrap() error

type Waiter

type Waiter struct {
	// contains filtered or unexported fields
}

Waiter ждёт операции одного API.

func NewWaiter

func NewWaiter(get Getter, opts Options) *Waiter

func (*Waiter) Wait

func (w *Waiter) Wait(ctx context.Context, op Operation) (Operation, error)

Wait опрашивает op до done. Завершённая с ошибкой — *FailedError вместе с самой операцией; оборванное ожидание — *PendingError.

Jump to

Keyboard shortcuts

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