Skip to content

Commit

Permalink
🐛 Make sure that the logger logs every message instead of exiting bef…
Browse files Browse the repository at this point in the history
…ore it prints anything due to a lack of 'next page'
  • Loading branch information
joshjennings98 committed May 8, 2024
1 parent ba3e7e5 commit 4ef474e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/20240508104451.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:bug: Make sure that the logger logs every message instead of exiting before it prints anything due to a lack of 'next page'
12 changes: 11 additions & 1 deletion utils/messages/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package messages
import (
"context"
"fmt"
"regexp"
"time"

"github.com/ARM-software/embedded-development-services-client-utils/utils/logging"
Expand Down Expand Up @@ -80,6 +81,8 @@ func (l *Logger) LogMarshallingError(rawMessage *any) {
}
}

var completedRegex = regexp.MustCompile(`<JOB COMPLETED [0-9]{2}:[0-9]{2}:[0-9]{2}>`)

func (l *Logger) LogMessagesCollection(ctx context.Context, messagePaginator pagination.IGenericPaginator) error {
for {
err := parallelisation.DetermineContextError(ctx)
Expand All @@ -90,7 +93,8 @@ func (l *Logger) LogMessagesCollection(ctx context.Context, messagePaginator pag
return fmt.Errorf("%w: missing paginator", commonerrors.ErrUndefined)
}
if !messagePaginator.HasNext() {
return nil
parallelisation.SleepWithContext(ctx, 200*time.Millisecond)
continue
}
m, err := messagePaginator.GetNext()
if err != nil {
Expand All @@ -102,7 +106,13 @@ func (l *Logger) LogMessagesCollection(ctx context.Context, messagePaginator pag
} else {
l.LogMessage(messageItem)
}
if message, ok := messageItem.GetMessageOk(); ok {
if completedRegex.MatchString(*message) {
break
}
}
}
return nil
}

// NewBasicAsynchronousMessageLogger creates an asynchronous logger for messages which prints them as they come.
Expand Down

0 comments on commit 4ef474e

Please sign in to comment.