Files
pipelines/internal/protocol/storage.go
T

80 lines
3.1 KiB
Go

package protocol
import "fmt"
const (
GetStorage = "get_storage"
SetStoragePolicy = "set_storage_policy"
PreviewStorageCleanup = "preview_storage_cleanup"
ApplyStorageCleanup = "apply_storage_cleanup"
StorageReply = "storage"
StoragePolicySaved = "storage_policy_saved"
StorageCleanupPreview = "storage_cleanup_preview"
StorageCleanupApplied = "storage_cleanup_applied"
)
// StoragePolicy is a server-wide opt-in policy. Age expiry and the size target
// are independent triggers; protected work is never removed to meet a target.
type StoragePolicy struct {
Enabled bool `json:"enabled"`
MaxAgeDays int `json:"max_age_days"`
MaxBytes int64 `json:"max_bytes"`
IncludeWorktrees bool `json:"include_worktrees"`
}
func (p StoragePolicy) Validate() error {
if p.MaxAgeDays < 0 || p.MaxAgeDays > 36500 {
return fmt.Errorf("max_age_days must be between 0 and 36500")
}
if p.MaxBytes < 0 || p.MaxBytes > 1<<50 {
return fmt.Errorf("max_bytes must be between 0 and 1125899906842624")
}
if p.Enabled && p.MaxAgeDays == 0 && p.MaxBytes == 0 {
return fmt.Errorf("automatic retention requires an age or size limit")
}
return nil
}
type StorageCategory struct {
ID string `json:"id"`
Label string `json:"label"`
Path string `json:"path,omitempty"`
Bytes int64 `json:"bytes"`
Files int64 `json:"files"`
Partial bool `json:"partial,omitempty"`
Error string `json:"error,omitempty"`
}
type StorageOverview struct {
Measurement string `json:"measurement"`
TotalBytes int64 `json:"total_bytes"`
Categories []StorageCategory `json:"categories"`
Policy StoragePolicy `json:"policy"`
MeasuredAt string `json:"measured_at"`
Partial bool `json:"partial"`
Warnings []string `json:"warnings,omitempty"`
AutomaticIntervalSeconds int `json:"automatic_interval_seconds"`
}
type StorageCleanupItem struct {
Kind string `json:"kind"`
ID string `json:"id"`
Path string `json:"path,omitempty"`
Bytes int64 `json:"bytes"`
Reason string `json:"reason,omitempty"`
Protected bool `json:"protected"`
}
type StorageCleanupResult struct {
Policy StoragePolicy `json:"policy"`
TotalBytes int64 `json:"total_bytes"`
ReclaimableBytes int64 `json:"reclaimable_bytes"`
TargetBytes int64 `json:"target_bytes"`
TargetReached bool `json:"target_reached"`
CandidateCount int `json:"candidate_count"`
ProtectedCount int `json:"protected_count"`
Items []StorageCleanupItem `json:"items"`
PreviewToken string `json:"preview_token,omitempty"`
RemovedCount int `json:"removed_count"`
RemovedBytes int64 `json:"removed_bytes"`
Applied bool `json:"applied"`
Errors []string `json:"errors,omitempty"`
}