Skip to content

Commit

Permalink
The last message is not necessarily the message with the highest sequ…
Browse files Browse the repository at this point in the history
…ence number

This avoids repeating messages over and over in certain situations.
  • Loading branch information
bertfrees committed Jan 3, 2025
1 parent 9e48311 commit e9ddc18
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

const (
VERSION = "2.2.0"
VERSION = "2.2.1-SNAPSHOT"
)

const (
Expand Down
31 changes: 19 additions & 12 deletions cli/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,20 @@ func (p PipelineLink) StylesheetParameters(paramReq StylesheetParametersRequest)

//Feeds the channel with the messages describing the job's execution
func getAsyncMessages(p PipelineLink, jobId string, messages chan Message) {
msgNum := -1
msgSeq := -1
for {
job, err := p.pipeline.Job(jobId, msgNum)
job, err := p.pipeline.Job(jobId, msgSeq)
if err != nil {
messages <- Message{Error: err}
close(messages)
return
}
n := msgNum
n := msgSeq
if len(job.Messages.Message) > 0 {
n = flattenMessages(job.Messages.Message, messages, job.Status, job.Messages.Progress, msgNum + 1, 0)
n = flattenMessages(job.Messages.Message, messages, job.Status, job.Messages.Progress, msgSeq + 1, 0)
}
if (n > msgNum) {
msgNum = n
if (n > msgSeq) {
msgSeq = n
} else {
messages <- Message{Progress: job.Messages.Progress}
}
Expand All @@ -290,18 +290,25 @@ func getAsyncMessages(p PipelineLink, jobId string, messages chan Message) {
}

//Flatten message coming from the Pipeline job and feed them into the channel
//Return the sequence number of the last inner message
func flattenMessages(from []pipeline.Message, to chan Message, status string, progress float64, firstNum int, depth int) (lastNum int) {
//Return the sequence number of the inner message with the highest sequence number
func flattenMessages(from []pipeline.Message, to chan Message, status string, progress float64, firstSeq int, depth int) (lastSeq int) {
lastSeq = -1
for _, msg := range from {
lastNum = msg.Sequence
if lastNum >= firstNum {
seq := msg.Sequence
if seq >= firstSeq {
to <- Message{Message: msg.Content, Level: msg.Level, Depth: depth, Status: status, Progress: progress}
if seq > lastSeq {
lastSeq = seq
}
}
if len(msg.Message) > 0 {
lastNum = flattenMessages(msg.Message, to, status, progress, firstNum, depth + 1)
seq := flattenMessages(msg.Message, to, status, progress, firstSeq, depth + 1)
if seq > lastSeq {
lastSeq = seq
}
}
}
return lastNum
return lastSeq
}

func jobRequestToPipeline(req JobRequest, p PipelineLink) (pReq pipeline.JobRequest, err error) {
Expand Down

0 comments on commit e9ddc18

Please sign in to comment.