Skip to content

Commit

Permalink
feat(goes/esgallery): add runtime to processor result
Browse files Browse the repository at this point in the history
  • Loading branch information
bounoable committed Sep 17, 2022
1 parent a566f89 commit 8f1da76
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions goes/esgallery/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"strings"
"sync"
"time"

"github.com/google/uuid"
"github.com/modernice/goes/aggregate"
Expand All @@ -20,7 +21,7 @@ import (
"github.com/modernice/media-tools/image"
)

// ProcessedTag is added to [Stack]s that were processed by a [*PostProcessor].
// ProcessedTag is added to [gallery.Stack]s that were processed by a [*PostProcessor].
const ProcessedTag = "processed"

// Processor post-processes [gallery.Stack]s and uploads the processed images
Expand All @@ -42,12 +43,15 @@ type ProcessorResult[StackID, ImageID ID] struct {
// was called manually, Trigger is nil.
Trigger event.Event

// StackID is the ID of processed [Stack].
// StackID is the ID of processed [gallery.Stack].
StackID StackID

// Images are the processed images.
Images []ProcessedImage[ImageID]

// Runtime is the time it took to process the [gallery.Stack].
Runtime time.Duration

// Applied is set to true if the post-processor applied the result to the
// gallery. This is the case if the [WithAutoApply] option is enabled.
// Consider passing the [DiscardResults] option to [PostProcessor.Run] when
Expand Down Expand Up @@ -454,6 +458,7 @@ func (q *processorQueue[Gallery, StackID, ImageID]) work() {
result ProcessorResult[StackID, ImageID]
err error
shouldPush = true
start = time.Now()
)

q.cfg.debugLog("handling %q event ...", evt.Name())
Expand All @@ -471,12 +476,14 @@ func (q *processorQueue[Gallery, StackID, ImageID]) work() {
}

result.Trigger = evt
result.Runtime = time.Since(start)

galleryID := pick.AggregateID(evt)

if q.processor.autoApply {
if err := q.apply(&result, galleryID); err != nil {
q.fail(fmt.Errorf("apply result: %w", err))
continue
}
}

Expand All @@ -486,6 +493,8 @@ func (q *processorQueue[Gallery, StackID, ImageID]) work() {
}

if shouldPush {
// Update the Runtime because q.apply() might have taken some time.
result.Runtime = time.Since(start)
q.push(result)
}
}
Expand Down

0 comments on commit 8f1da76

Please sign in to comment.