Skip to content

Commit cb6f434

Browse files
committed
Fix(github): avoid running into rate limits
1 parent d12f302 commit cb6f434

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

cmd/bot/main.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ var (
3232

3333
// for github crawling
3434
githubToken string = ""
35+
36+
checkInterval time.Duration = 15 * time.Minute
3537
)
3638

3739
func init() {
@@ -127,11 +129,16 @@ func main() {
127129
for {
128130
slog.DebugContext(ctx, "checking...")
129131
if err := content.Do(ctx, c); err != nil {
130-
slog.ErrorContext(ctx, err.Error())
131-
os.Exit(1)
132+
if !errors.Is(err, content.ErrCouldNotContent) {
133+
slog.ErrorContext(ctx, err.Error())
134+
os.Exit(1)
135+
}
136+
slog.DebugContext(ctx, "backing off...")
137+
break
138+
132139
}
133140

134-
time.Sleep(5 * time.Minute)
141+
time.Sleep(checkInterval)
135142
}
136143
return nil
137144
},

internal/content/content.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package content
22

33
import (
44
"context"
5-
"fmt"
5+
"errors"
66
"log/slog"
77
"strings"
88

@@ -13,7 +13,8 @@ import (
1313
)
1414

1515
var (
16-
provider github.Provider
16+
provider github.Provider
17+
ErrCouldNotContent = errors.New("could not get content")
1718
)
1819

1920
func Start(token string, cacheClient cache.Client) error {
@@ -28,7 +29,8 @@ func Start(token string, cacheClient cache.Client) error {
2829
func Do(ctx context.Context, c bluesky.Client) error {
2930
p, err := provider.GetContentToPublish()
3031
if err != nil {
31-
return fmt.Errorf("could not get content: %v", err)
32+
slog.Error("error fetching content", slog.Any("err", err))
33+
return ErrCouldNotContent
3234
}
3335

3436
if p == nil {

0 commit comments

Comments
 (0)