Documentation
¶
Index ¶
- Constants
- Variables
- func RunScheduler(ctx context.Context, service *Service)
- type Archive
- type Archiver
- type CreateOutcome
- type CreateResult
- type Cursor
- type DiskStore
- func (s *DiskStore) Backend() string
- func (s *DiskStore) Delete(ctx context.Context, key string) error
- func (s *DiskStore) Open(ctx context.Context, key string, sizeBytes int64) (io.ReadCloser, error)
- func (s *DiskStore) Put(ctx context.Context, key string, write func(io.Writer) error) (StoredObject, error)
- type Download
- type ListQuery
- type Page
- type Policy
- type S3Store
- func (s *S3Store) Backend() string
- func (s *S3Store) Delete(ctx context.Context, key string) error
- func (s *S3Store) Open(ctx context.Context, key string, sizeBytes int64) (io.ReadCloser, error)
- func (s *S3Store) Put(ctx context.Context, key string, write func(io.Writer) error) (StoredObject, error)
- type Scope
- type Service
- func (a *Service) Create(ctx context.Context, scope Scope) (result CreateResult, err error)
- func (a *Service) GetPolicy(ctx context.Context, scope Scope) (Policy, error)
- func (a *Service) List(ctx context.Context, scope Scope, query ListQuery) (Page, error)
- func (a *Service) Open(ctx context.Context, scope Scope, archiveID uuid.UUID) (Download, error)
- func (a *Service) RunDue(ctx context.Context) (processed int, locked bool, err error)
- func (a *Service) SetPolicy(ctx context.Context, scope Scope, policy Policy) error
- type Store
- type StoredObject
Constants ¶
const MaxArchiveAfterWeeks = int((1<<63 - 1) / (7 * 24 * time.Hour))
MaxArchiveAfterWeeks bounds the cutoff calculation to a time.Duration.
Variables ¶
Functions ¶
func RunScheduler ¶
Types ¶
type Archive ¶
type Archive struct {
ID uuid.UUID
ClientID uuid.UUID
FileName string
SizeBytes int64
SHA256 [32]byte
LogCount int64
CutoffAt time.Time
FromAt time.Time
ToAt time.Time
CreatedAt time.Time
}
Archive describes a completed ZIP without exposing its storage location.
type Archiver ¶
type Archiver interface {
// GetPolicy returns a disabled policy when the client has no rule.
GetPolicy(ctx context.Context, scope Scope) (Policy, error)
// SetPolicy replaces the rule idempotently. Enabling or changing its age
// schedules the first automatic run that many weeks from now; an unchanged
// rule preserves its schedule. Disabling preserves archives and does not
// cancel an in-progress Create; changes apply to the next build.
SetPolicy(ctx context.Context, scope Scope, policy Policy) error
// Create synchronously archives the fixed set of eligible logs. Only logs
// safely written to the completed archive are deleted. An error does not
// imply rollback: an interrupted commit can have an uncertain outcome.
// Missing rules, empty cohorts and concurrent builds return skip outcomes,
// not errors. Recovery runs under exclusive client ownership. Calling Create
// directly neither waits for nor changes the automatic schedule.
Create(ctx context.Context, scope Scope) (CreateResult, error)
// List returns completed archives ordered by CreatedAt DESC, ID DESC.
List(ctx context.Context, scope Scope, query ListQuery) (Page, error)
// Open returns completed archive content. The caller must close it and
// handle read errors; the stream does not promise seeking or Range support.
Open(ctx context.Context, scope Scope, archiveID uuid.UUID) (Download, error)
}
Archiver manages client policies and completed archives. It validates client ownership, but callers are responsible for user authorization.
type CreateOutcome ¶
type CreateOutcome string
const ( Created CreateOutcome = "created" SkippedNoLogs CreateOutcome = "skipped_no_logs" SkippedDisabled CreateOutcome = "skipped_disabled" SkippedBusy CreateOutcome = "skipped_busy" )
type CreateResult ¶
type CreateResult struct {
Outcome CreateOutcome
Archive *Archive // non-nil only for Created
}
type DiskStore ¶
type DiskStore struct {
// contains filtered or unexported fields
}
type Download ¶
type Download struct {
Archive Archive
Content io.ReadCloser
}
type S3Store ¶
type S3Store struct {
// contains filtered or unexported fields
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewArchiveService ¶
NewArchiveService uses store for archive content. A nil store permits metadata reads and policy disabling, but not enabling, creating or opening archives.
func (*Service) RunDue ¶
RunDue archives every due client while holding the scheduler lock, then schedules each one its policy's number of weeks later. locked is false when another instance is running a pass. Per-client failures are logged and retried after 15 minutes instead of waiting for the next full policy interval.
type Store ¶
type Store interface {
// Backend is the stable storage_backend value persisted with each archive.
Backend() string
// Put calls write synchronously, at most once, with a streaming writer.
// Success means write succeeded and all bytes are durably stored and available
// through Open; metadata describes those exact bytes. An error may leave
// content behind: callers must confirm database rollback before Delete.
Put(ctx context.Context, key string, write func(io.Writer) error) (StoredObject, error)
// Open rejects missing content or a size mismatch. The caller closes the
// stream; seeking and Range support are not required.
Open(ctx context.Context, key string, sizeBytes int64) (io.ReadCloser, error)
// Delete removes both completed content and any staging artifacts for key.
// It is idempotent for missing content. Callers must hold exclusive build
// ownership and confirm the archive is neither ready nor possibly committed.
Delete(ctx context.Context, key string) error
}
Store persists archive content independently of policies, ZIP generation and PostgreSQL. Keys are slash-separated relative object names, not public paths.
func NewDiskStore ¶
NewDiskStore returns nil for an empty directory, leaving storage unconfigured.