diff --git a/Dockerfile b/Dockerfile index 9166b70..364b477 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,10 @@ RUN go build -o brassite ./cmd/brassite/main.go FROM alpine:3.20 AS runtime +WORKDIR /usr/local/src/brassite + +COPY . . + COPY --from=builder /build/brassite /usr/local/bin/brassite CMD ["/usr/local/bin/brassite"] \ No newline at end of file diff --git a/cmd/brassite/main.go b/cmd/brassite/main.go index e8a5c6d..21a4b38 100644 --- a/cmd/brassite/main.go +++ b/cmd/brassite/main.go @@ -101,6 +101,7 @@ func main() { } <-exitSignal + slog.Info("Shutting down Brassite") } func runWorker(feed brassite.Feed) { @@ -108,13 +109,22 @@ func runWorker(feed brassite.Feed) { slog.Debug("Starting worker", slog.String("feed_name", feed.Name), slog.String("url", feed.URL), slog.Duration("interval", feed.Interval)) ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5) + hub := sentry.CurrentHub().Clone() + hub.Scope().SetTag("feed_name", feed.Name) + hub.Scope().SetExtras(map[string]interface{}{ + "feed_name": feed.Name, + "url": feed.URL, + "interval": feed.Interval.String(), + "without_content": feed.WithoutContent, + }) + ctx = sentry.SetHubOnContext(ctx, hub) // Call the feed parser request, err := http.NewRequestWithContext(ctx, http.MethodGet, feed.URL, nil) if err != nil { slog.Error("Failed to create request", slog.Any("error", err), slog.String("feed_name", feed.Name)) cancel() - sentry.CaptureException(err) + sentry.GetHubFromContext(ctx).CaptureException(err) time.Sleep(feed.Interval) continue } @@ -134,7 +144,7 @@ func runWorker(feed brassite.Feed) { if err != nil { slog.Error("Failed to send request", slog.Any("error", err), slog.String("feed_name", feed.Name)) cancel() - sentry.CaptureException(err) + sentry.GetHubFromContext(ctx).CaptureException(err) time.Sleep(feed.Interval) continue } @@ -145,11 +155,14 @@ func runWorker(feed brassite.Feed) { slog.Error("Failed to parse feed", slog.Any("error", err), slog.String("feed_name", feed.Name)) _ = response.Body.Close() cancel() - sentry.CaptureException(err) + sentry.GetHubFromContext(ctx).CaptureException(err) time.Sleep(feed.Interval) continue } + // Don't take too long to close the body + _ = response.Body.Close() + // Only select the new items by using now - interval var newItems []*gofeed.Item for _, item := range remoteFeed.Items { @@ -201,7 +214,7 @@ func runWorker(feed brassite.Feed) { if err != nil { slog.Error("Failed to deliver to Discord", slog.String("feed_name", feed.Name), slog.Any("error", err)) - sentry.CaptureException(err) + sentry.GetHubFromContext(ctx).CaptureException(err) } } @@ -216,7 +229,6 @@ func runWorker(feed brassite.Feed) { // } } - _ = response.Body.Close() cancel() time.Sleep(feed.Interval) diff --git a/delivery_discord.go b/delivery_discord.go index 9e08646..8e1f749 100644 --- a/delivery_discord.go +++ b/delivery_discord.go @@ -109,6 +109,7 @@ func DeliverToDiscord(ctx context.Context, webhookURL string, feedItem FeedItem, } request.Header.Set("Content-Type", "application/json") + request.Header.Set("User-Agent", "Brassite/1.0") response, err := http.DefaultClient.Do(request) if err != nil {