worker notice default limit
This commit is contained in:
@@ -29,7 +29,7 @@ type NoticeWorker struct {
|
||||
}
|
||||
|
||||
func NewNoticeWorker(mongo *mongo.ConnectionManager, logger logger.Logger, notify *notification.SDK, noticeRepo notice.Repository, tenderRepo tender.TenderRepository, glmService *glm.SDK, scraper scraper.SDK, processingLimit int) *NoticeWorker {
|
||||
if processingLimit <= 0 {
|
||||
if processingLimit < 0 {
|
||||
processingLimit = 5 // Default limit
|
||||
}
|
||||
return &NoticeWorker{
|
||||
@@ -102,13 +102,12 @@ func (w *NoticeWorker) Run() {
|
||||
|
||||
w.cleanupProcessedNotices()
|
||||
|
||||
limit := 10
|
||||
skip := 0
|
||||
processedCount := 0
|
||||
maxToProcess := w.ProcessingLimit
|
||||
|
||||
for processedCount < maxToProcess {
|
||||
notices, _, err := w.NoticeRepo.GetUnProcessedNotices(context.Background(), limit, skip)
|
||||
for maxToProcess == 0 || processedCount < maxToProcess {
|
||||
notices, _, err := w.NoticeRepo.GetUnProcessedNotices(context.Background(), skip, maxToProcess)
|
||||
if err != nil {
|
||||
w.Logger.Error("Failed to get notices", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
@@ -124,6 +123,14 @@ func (w *NoticeWorker) Run() {
|
||||
}
|
||||
|
||||
for _, n := range notices {
|
||||
if maxToProcess > 0 && processedCount >= maxToProcess {
|
||||
w.Logger.Info("Reached maximum processing limit, stopping", map[string]interface{}{
|
||||
"processed_count": processedCount,
|
||||
"max_to_process": maxToProcess,
|
||||
})
|
||||
break
|
||||
}
|
||||
|
||||
w.Logger.Info("Notice", map[string]interface{}{
|
||||
"notice": n.ID.Hex(),
|
||||
})
|
||||
@@ -179,14 +186,10 @@ func (w *NoticeWorker) Run() {
|
||||
}
|
||||
}
|
||||
|
||||
skip += limit
|
||||
skip += maxToProcess
|
||||
|
||||
// Check if we've reached the processing limit
|
||||
if processedCount >= maxToProcess {
|
||||
w.Logger.Info("Reached maximum processing limit, stopping", map[string]interface{}{
|
||||
"processed_count": processedCount,
|
||||
"max_to_process": maxToProcess,
|
||||
})
|
||||
// Check if we need to exit outer loop (break from inner loop means we hit the limit)
|
||||
if maxToProcess > 0 && processedCount >= maxToProcess {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user