Skip to content

Commit

Permalink
Merge pull request #129 from traP-jp/fix-break-condition
Browse files Browse the repository at this point in the history
メッセージ取得のforループの終了条件に、実際に返ってきたメッセージ数を使うようにした
  • Loading branch information
oribe1115 authored Jan 14, 2024
2 parents 08a2aee + e9e57a4 commit a437224
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions server/traqmessage/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,23 @@ func (m *MessagePoller) Run() {
checkpointMutex.Lock()

now := time.Now()
var collectedMessageCount int64
var collectedMessageCount int
for i := 0; ; i += 100 {
messages, err := collectMessages(lastCheckpoint, now, i)
if err != nil {
slog.Error(fmt.Sprintf("Failled to polling messages: %v", err))
break
}

slog.Info(fmt.Sprintf("Collect %d messages", messages.TotalHits))
collectedMessageCount += messages.TotalHits
tmpMessageCount := len(messages.Hits)

slog.Info(fmt.Sprintf("Collect %d messages", tmpMessageCount))
collectedMessageCount += tmpMessageCount

// 取得したメッセージを使っての処理の呼び出し
m.processor.enqueue(&messages.Hits)

if messages.TotalHits < 100 {
if tmpMessageCount < 100 {
break
}
}
Expand Down

0 comments on commit a437224

Please sign in to comment.