forked from barrydeen/haven
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblastr.go
More file actions
35 lines (32 loc) · 938 Bytes
/
Copy pathblastr.go
File metadata and controls
35 lines (32 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"context"
"errors"
"log/slog"
"time"
"github.com/nbd-wtf/go-nostr"
)
func blast(ctx context.Context, ev *nostr.Event) {
var successCount int
for _, url := range config.BlastrRelays {
timeout := time.Second * time.Duration(config.BlastrTimeoutSeconds)
ctx, cancel := context.WithTimeout(ctx, timeout)
relay, err := pool.EnsureRelay(url)
if err != nil {
cancel()
slog.Error("⛓️💥 error connecting to relay", "relay", url, "error", err)
continue
}
if err := relay.Publish(ctx, *ev); err != nil {
if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
slog.Error("🚫 timeout publishing to relay", "relay", url, "timeout", timeout)
} else {
slog.Error("🚫 error publishing to relay", "relay", url, "error", err)
}
} else {
successCount++
}
cancel()
}
slog.Info("🔫 blasted event", "id", ev.ID, "relays", successCount)
}