Add publish output progress counting remaining number of packages

This commit is contained in:
Oliver Sauder
2018-05-17 15:44:49 +02:00
committed by Lorenzo Bolla
parent 3cd168c44d
commit f09a273ad7
15 changed files with 106 additions and 27 deletions

View File

@@ -4,6 +4,8 @@ import (
"bytes"
"fmt"
"sync"
"github.com/aptly-dev/aptly/aptly"
)
// Output represents a safe standard output of task
@@ -13,6 +15,13 @@ type Output struct {
output *bytes.Buffer
}
// PublishOutput specific output for publishing api
type PublishOutput struct {
*Output
PublishDetail
barType *aptly.BarType
}
// NewOutput creates new output
func NewOutput() *Output {
return &Output{mu: &sync.Mutex{}, output: &bytes.Buffer{}}
@@ -54,20 +63,43 @@ func (t *Output) Flush() {
}
// InitBar is needed for progress compatibility
func (t *Output) InitBar(count int64, isBytes bool) {
func (t *Output) InitBar(count int64, isBytes bool, barType aptly.BarType) {
// Not implemented
}
// InitBar publish output specific
func (t *PublishOutput) InitBar(count int64, isBytes bool, barType aptly.BarType) {
t.barType = &barType
if barType == aptly.BarPublishGeneratePackageFiles {
t.TotalNumberOfPackages = count
t.RemainingNumberOfPackages = count
t.Store(t)
}
}
// ShutdownBar is needed for progress compatibility
func (t *Output) ShutdownBar() {
// Not implemented
}
// ShutdownBar publish output specific
func (t *PublishOutput) ShutdownBar() {
t.barType = nil
}
// AddBar is needed for progress compatibility
func (t *Output) AddBar(count int) {
// Not implemented
}
// AddBar publish output specific
func (t *PublishOutput) AddBar(count int) {
if t.barType != nil && *t.barType == aptly.BarPublishGeneratePackageFiles {
t.RemainingNumberOfPackages--
t.Store(t)
}
}
// SetBar sets current position for progress bar
func (t *Output) SetBar(count int) {
// Not implemented

View File

@@ -12,6 +12,13 @@ type Detail struct {
atomic.Value
}
// PublishDetail represents publish task details
type PublishDetail struct {
*Detail
TotalNumberOfPackages int64
RemainingNumberOfPackages int64
}
// Process is a function implementing the actual task logic
type Process func(out *Output, detail *Detail) error