Help us shape the future of Go! Take the 2026 Go Developer Survey

operations

package
v3.1.31 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package operations provides tracking for long-running operations with real-time progress updates via Server-Sent Events (SSE).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeSSE

func ServeSSE(w http.ResponseWriter, r *http.Request, opID string)

ServeSSE serves Server-Sent Events for operation progress

Types

type Manager

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

Manager handles operation tracking

func GetManager

func GetManager() *Manager

GetManager returns the global operation manager

func (*Manager) GetOperation

func (m *Manager) GetOperation(id string) (*Operation, bool)

GetOperation retrieves an operation by ID

func (*Manager) StartOperation

func (m *Manager) StartOperation(ctx context.Context, id string, opType OperationType, userID int64, phases []string) *Operation

StartOperation creates and registers a new operation

type Operation

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

Operation tracks a long-running operation

func (*Operation) Cancel

func (op *Operation) Cancel()

Cancel cancels the operation

func (*Operation) Complete

func (op *Operation) Complete(result map[string]any)

Complete marks the operation as complete

func (*Operation) Context

func (op *Operation) Context() context.Context

Context returns the operation's context

func (*Operation) Fail

func (op *Operation) Fail(err error)

Fail marks the operation as failed

func (*Operation) GetProgress

func (op *Operation) GetProgress() ProgressUpdate

GetProgress returns current progress state

func (*Operation) ID

func (op *Operation) ID() string

ID returns the operation ID

func (*Operation) NextPhase

func (op *Operation) NextPhase()

NextPhase moves to the next phase

func (*Operation) SetMetadata

func (op *Operation) SetMetadata(key string, value any)

SetMetadata sets operation metadata

func (*Operation) Subscribe

func (op *Operation) Subscribe() <-chan ProgressUpdate

Subscribe to operation progress updates

func (*Operation) Unsubscribe

func (op *Operation) Unsubscribe(ch <-chan ProgressUpdate)

Unsubscribe from operation updates

func (*Operation) UpdateBytes

func (op *Operation) UpdateBytes(done, total int64)

UpdateBytes updates byte progress

func (*Operation) UpdateItems

func (op *Operation) UpdateItems(done, total int)

UpdateItems updates item progress

func (*Operation) UpdateProgress

func (op *Operation) UpdateProgress(progress int, message string)

UpdateProgress updates the operation progress

type OperationStatus

type OperationStatus string

OperationStatus represents the current status of an operation

const (
	StatusPending   OperationStatus = "pending"
	StatusRunning   OperationStatus = "running"
	StatusComplete  OperationStatus = "complete"
	StatusFailed    OperationStatus = "failed"
	StatusCancelled OperationStatus = "cancelled"
)

type OperationType

type OperationType string

OperationType represents the type of long-running operation

const (
	OpChunkedUpload  OperationType = "chunked_upload"
	OpRepoMirrorSync OperationType = "mirror_sync"
	OpRepoPush       OperationType = "repo_push"
	OpRepoClone      OperationType = "repo_clone"
	OpWikiGenerate   OperationType = "wiki_generate"
	OpBatchOperation OperationType = "batch_operation"
)

type Phase

type Phase struct {
	Name     string          `json:"name"`
	Status   OperationStatus `json:"status"`
	Progress int             `json:"progress"` // 0-100
	Message  string          `json:"message,omitempty"`
}

Phase represents a phase within an operation

type ProgressUpdate

type ProgressUpdate struct {
	OperationID  string          `json:"operation_id"`
	Type         OperationType   `json:"type"`
	Status       OperationStatus `json:"status"`
	CurrentPhase string          `json:"current_phase,omitempty"`
	Phases       []Phase         `json:"phases,omitempty"`
	Progress     int             `json:"progress"` // Overall progress 0-100
	BytesTotal   int64           `json:"bytes_total,omitempty"`
	BytesDone    int64           `json:"bytes_done,omitempty"`
	ItemsTotal   int             `json:"items_total,omitempty"`
	ItemsDone    int             `json:"items_done,omitempty"`
	Message      string          `json:"message,omitempty"`
	Error        string          `json:"error,omitempty"`
	StartedAt    time.Time       `json:"started_at"`
	UpdatedAt    time.Time       `json:"updated_at"`
	EstimatedETA *time.Time      `json:"estimated_eta,omitempty"`
	SpeedBPS     int64           `json:"speed_bps,omitempty"` // bytes per second
	Metadata     map[string]any  `json:"metadata,omitempty"`
}

ProgressUpdate represents a progress update event

Source Files

  • progress.go

Jump to

Keyboard shortcuts

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