Skip to content

Commit

Permalink
Merge pull request #128 from traP-jp/fixPollingOffset_spelling
Browse files Browse the repository at this point in the history
投稿取得件数が100件を超えた際のoffsetの増分を1→100に / `processer`→`processor`
  • Loading branch information
oribe1115 authored Jan 13, 2024
2 parents 36e8755 + 800c293 commit 08a2aee
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions server/traqmessage/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import (
)

type MessagePoller struct {
processer *messageProcesser
processor *messageProcessor
}

func NewMessagePoller() *MessagePoller {
return &MessagePoller{
processer: &messageProcesser{
processor: &messageProcessor{
queue: make(chan *[]traq.Message),
},
}
}

// go routineの中で呼ぶこと
func (m *MessagePoller) Run() {
go m.processer.run()
go m.processor.run()

pollingInterval := time.Minute * 3

Expand All @@ -40,7 +40,7 @@ func (m *MessagePoller) Run() {

now := time.Now()
var collectedMessageCount int64
for i := 0; ; i++ {
for i := 0; ; i += 100 {
messages, err := collectMessages(lastCheckpoint, now, i)
if err != nil {
slog.Error(fmt.Sprintf("Failled to polling messages: %v", err))
Expand All @@ -51,7 +51,7 @@ func (m *MessagePoller) Run() {
collectedMessageCount += messages.TotalHits

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

if messages.TotalHits < 100 {
break
Expand All @@ -66,12 +66,12 @@ func (m *MessagePoller) Run() {
}

// 通知メッセージの検索と通知処理のjobを処理する
type messageProcesser struct {
type messageProcessor struct {
queue chan *[]traq.Message
}

// go routineの中で呼ぶ
func (m *messageProcesser) run() {
func (m *messageProcessor) run() {
for {
select {
case messages := <-m.queue:
Expand All @@ -80,11 +80,11 @@ func (m *messageProcesser) run() {
}
}

func (m *messageProcesser) enqueue(messages *[]traq.Message) {
func (m *messageProcessor) enqueue(messages *[]traq.Message) {
m.queue <- messages
}

func (m *messageProcesser) process(messages []traq.Message) {
func (m *messageProcessor) process(messages []traq.Message) {
messageList, err := ConvertMessageHits(messages)
if err != nil {
slog.Error(fmt.Sprintf("Failled to convert messages: %v", err))
Expand Down

0 comments on commit 08a2aee

Please sign in to comment.