operations

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 6 Imported by: 1 module, 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

Index

Constants

View Source
const (
	ProgressEvent  = "operation progress"
	CompletedEvent = "operation completed"
	ErrorEvent     = "operation error"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcast

type Broadcast func(event string, args ...string)

Broadcast publishes a websocket-compatible event and its string arguments.

type Manager

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

Manager tracks asynchronous operations for one server.

func NewManager

func NewManager(ctx context.Context, broadcast Broadcast) *Manager

func (*Manager) Abort

func (m *Manager) Abort(id uuid.UUID) bool

Abort cancels an active operation.

func (*Manager) Add

func (m *Manager) Add(op Operation) (uuid.UUID, context.CancelFunc)

Add registers an operation and starts its heartbeat progress publisher.

func (*Manager) Complete

func (m *Manager) Complete(id uuid.UUID) bool

Complete emits final progress and completion, then removes the operation.

func (*Manager) Context

func (m *Manager) Context(id uuid.UUID) (context.Context, bool)

Context returns the cancelable context associated with an operation.

func (*Manager) Fail

func (m *Manager) Fail(id uuid.UUID, message string) bool

Fail emits an operation error, then removes the operation.

func (*Manager) Get

func (m *Manager) Get(id uuid.UUID) (Operation, bool)

func (*Manager) List

func (m *Manager) List() map[uuid.UUID]Operation

type Operation

type Operation struct {
	Type            string         `json:"type"`
	Path            string         `json:"path,omitempty"`
	DestinationPath string         `json:"destination_path,omitempty"`
	StartTime       time.Time      `json:"start_time"`
	BytesProcessed  *atomic.Uint64 `json:"-"`
	BytesTotal      *atomic.Uint64 `json:"-"`
	FilesProcessed  *atomic.Uint64 `json:"-"`
}

Operation describes a long-running filesystem operation.

func (Operation) MarshalJSON

func (o Operation) MarshalJSON() ([]byte, error)

MarshalJSON snapshots atomic counters as ordinary JSON numbers.

Jump to

Keyboard shortcuts

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