fix: 初验针对修改
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package ingest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -63,17 +64,36 @@ func enqueuePayloadWithDB(db *gorm.DB, logEventID uint, payloadJSON string) (uin
|
||||
return row.ID, nil
|
||||
}
|
||||
|
||||
func StartAlertDispatcher() {
|
||||
func StartAlertDispatcher(ctx context.Context) {
|
||||
owner := dispatcherOwner()
|
||||
go func() {
|
||||
startWorker("alert_dispatcher", func() error {
|
||||
ticker := time.NewTicker(2 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for range ticker.C {
|
||||
if _, err := ProcessAlertOutboxBatch(impl.DBService, 20, owner); err != nil {
|
||||
log.Printf("logs: alert outbox dispatch: %v", err)
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
case <-ticker.C:
|
||||
if _, err := ProcessAlertOutboxBatch(impl.DBService, 20, owner); err != nil {
|
||||
markWorkerError("alert_dispatcher", err)
|
||||
log.Printf("logs: alert outbox dispatch: %v", err)
|
||||
continue
|
||||
}
|
||||
if depth, err := alertOutboxQueueDepth(ctx); err == nil {
|
||||
markWorkerQueueDepth("alert_dispatcher", depth)
|
||||
}
|
||||
markWorkerSucceeded("alert_dispatcher")
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
func alertOutboxQueueDepth(ctx context.Context) (int64, error) {
|
||||
var depth int64
|
||||
err := impl.DBService.WithContext(ctx).Model(&models.AlertOutbox{}).
|
||||
Where("status IN ?", []string{outboxStatusPending, outboxStatusRetrying, outboxStatusProcessing}).
|
||||
Count(&depth).Error
|
||||
return depth, err
|
||||
}
|
||||
|
||||
func dispatcherOwner() string {
|
||||
|
||||
Reference in New Issue
Block a user