make delay only affect the step

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2024-10-22 10:04:56 +02:00
parent dd66ee19d1
commit 72e3e54fe0
2 changed files with 11 additions and 4 deletions

View File

@@ -75,9 +75,12 @@ func (pp *Postprocessing) CurrentStep() interface{} {
}
// Delay will sleep the configured time then continue
func (pp *Postprocessing) Delay() interface{} {
time.Sleep(pp.config.Delayprocessing)
return pp.next(events.PPStepDelay)
func (pp *Postprocessing) Delay(f func(next interface{})) {
next := pp.next(events.PPStepDelay)
go func() {
time.Sleep(pp.config.Delayprocessing)
f(next)
}()
}
// BackoffDuration calculates the duration for exponential backoff based on the number of failures.

View File

@@ -149,7 +149,11 @@ func (pps *PostprocessingService) processEvent(e events.Event) error {
pps.log.Error().Str("uploadID", ev.UploadID).Err(err).Msg("cannot get upload")
return fmt.Errorf("%w: cannot get upload", ErrEvent)
}
next = pp.Delay()
pp.Delay(func(next interface{}) {
if err := events.Publish(ctx, pps.pub, next); err != nil {
pps.log.Error().Err(err).Msg("cannot publish event")
}
})
case events.UploadReady:
if ev.Failed {
// the upload failed - let's keep it around for a while - but mark it as finished