Files
pages/internal/server/ordoschnellic.go
T
Anya Tokugawa a36934e72c
Build and publish container images / images (push) Successful in 16m17s
Release container images / release (push) Successful in 39s
Fix event log writer contention and report persistence failures safely
Take the SQLite writer lock before reading job/policy facts, bound acquisition and cancellation, preserve atomic raw logs and counters, and avoid replaying successful business operations on logging failure. Tested the isolated nine-file release slice with the full Go suite, race tests and go vet.
2026-11-01 19:40:26 +09:00

50 lines
1.8 KiB
Go

package server
import (
"context"
"fmt"
"net/http"
"time"
"pageswiki/internal/ordoschnellic"
"pageswiki/internal/store"
)
type notificationDeliveryQueue struct{ store *store.Store }
func (q notificationDeliveryQueue) Cleanup(ctx context.Context, at time.Time) error {
return q.store.CleanupNotificationPush(ctx, at)
}
func (q notificationDeliveryQueue) Claim(ctx context.Context, at time.Time) (*ordoschnellic.PushDelivery, error) {
return q.store.ClaimNotificationPushAt(ctx, at)
}
func (q notificationDeliveryQueue) DeferFocused(ctx context.Context, d *ordoschnellic.PushDelivery, at time.Time) error {
return q.store.DeferFocusedNotificationPushAt(ctx, d, at)
}
func (q notificationDeliveryQueue) Finish(ctx context.Context, d *ordoschnellic.PushDelivery, outcome ordoschnellic.Outcome, at time.Time) error {
return q.store.FinishNotificationPushAt(ctx, d, outcome.Retry, outcome.Expired, at)
}
func notificationDeliveryClient() *http.Client {
// Preserve pinned public-address dialing and never follow push redirects.
client := calendarSourceClient()
client.Timeout = 5 * time.Second
client.CheckRedirect = func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }
return client
}
func (s *Server) deliverNotificationPushContext(ctx context.Context, job *store.EventJob) error {
dispatcher := ordoschnellic.Dispatcher{
Queue: notificationDeliveryQueue{s.store},
Sender: ordoschnellic.WebPush{Keys: s.notificationPushKeys, Client: notificationDeliveryClient()},
}
stats, err := dispatcher.Run(ctx)
if err != nil {
return err
}
if stats.Sent+stats.Failed > 0 {
s.addEventProgressLog(ctx, job, fmt.Sprintf("component=%s push sent=%d failed=%d (no payload or endpoint logged)", ordoschnellic.Component, stats.Sent, stats.Failed))
}
return nil
}