Skip to content

Commit

Permalink
Call ScheduleNextCheck in a delay function.
Browse files Browse the repository at this point in the history
  • Loading branch information
shizunge committed Nov 23, 2023
1 parent 1efa6f7 commit 2755056
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions internal/reader/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func RefreshFeed(store *storage.Storage, userID, feedID int64, forceRefresh bool
}

weeklyEntryCount := 0
newTTL := 0
if config.Opts.PollingScheduler() == model.SchedulerEntryFrequency {
var weeklyCountErr error
weeklyEntryCount, weeklyCountErr = store.WeeklyFeedEntryCount(userID, feedID)
Expand All @@ -225,7 +226,15 @@ func RefreshFeed(store *storage.Storage, userID, feedID int64, forceRefresh bool
}

originalFeed.CheckedNow()
originalFeed.ScheduleNextCheck(weeklyEntryCount, 0)
defer func() {
originalFeed.ScheduleNextCheck(weeklyEntryCount, newTTL)
slog.Debug("Updating next check date based on TTL",
slog.Int64("user_id", userID),
slog.Int64("feed_id", feedID),
slog.Time("new_next_check_at", originalFeed.NextCheckAt),
slog.Int("ttl", newTTL),
)
}()

requestBuilder := fetcher.NewRequestBuilder()
requestBuilder.WithUsernameAndPassword(originalFeed.Username, originalFeed.Password)
Expand Down Expand Up @@ -279,13 +288,7 @@ func RefreshFeed(store *storage.Storage, userID, feedID int64, forceRefresh bool
}

// If the feed has a TTL defined, we use it to make sure we don't check it too often.
originalFeed.ScheduleNextCheck(weeklyEntryCount, updatedFeed.TTL)
slog.Debug("Updating next check date based on TTL",
slog.Int64("user_id", userID),
slog.Int64("feed_id", feedID),
slog.Time("new_next_check_at", originalFeed.NextCheckAt),
slog.Int("ttl", updatedFeed.TTL),
)
newTTL = updatedFeed.TTL

originalFeed.Entries = updatedFeed.Entries
processor.ProcessFeedEntries(store, originalFeed, user, forceRefresh)
Expand Down

0 comments on commit 2755056

Please sign in to comment.