Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

投稿取得件数が100件を超えた際のoffsetの増分を1→100に / processerprocessor #128

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading