Skip to content

Commit

Permalink
Improve error handling for tweetfinder timeout
Browse files Browse the repository at this point in the history
Enhanced the tweetfinder error handling by introducing a unique error `ErrTimeoutSelectFinder` used for instances of tweetfinder timeouts. Modified corresponding sections in `pool.go` and `watcher.go` to throw and process this new error, respectively. This ensures timeouts are treated as unique error cases, promoting better error identification and management.
  • Loading branch information
lueurxax committed Dec 27, 2023
1 parent 392c66a commit bc03a24
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions internal/tweetfinder/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tweetfinder
import "errors"

var (
ErrNoTops = errors.New("no top tweets")
ErrNotFound = errors.New("not found")
ErrNoTops = errors.New("no top tweets")
ErrNotFound = errors.New("not found")
ErrTimeoutSelectFinder = errors.New("timeout select finder")
)
5 changes: 5 additions & 0 deletions internal/tweetfinder/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,15 @@ func (p *pool) getFinder(ctx context.Context) (Finder, int, error) {

ticker := time.NewTicker(time.Second)

timer := time.NewTimer(time.Minute)
defer timer.Stop()

for !ok {
select {
case <-ctx.Done():
return nil, 0, ctx.Err()
case <-timer.C:
return nil, 0, ErrTimeoutSelectFinder
case <-p.releaseSignal:
break
case <-ticker.C:
Expand Down
2 changes: 1 addition & 1 deletion internal/tweetseditor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (e *editor) longStorySend(ctx context.Context) error {

e.log.WithField("tweets", tweetsStr).Debug("long story summary generation request")

request := ""
var request string
if len(e.longStoryMessages) == 0 {
request = fmt.Sprintf(longStoryPrompt, tweetsStr)
} else {
Expand Down
4 changes: 4 additions & 0 deletions internal/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ func (w *watcher) searchWithQuery(ctx context.Context, query string, start time.

w.logger.WithError(err).Error("find tweets")

if errors.Is(err, tweetfinder.ErrTimeoutSelectFinder) {
return
}

continue
}

Expand Down

0 comments on commit bc03a24

Please sign in to comment.