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 { if err := ctx.Err(); err != nil { return err } if !s.store.SupportsNotificationPush() { return store.ErrBackendFeatureUnavailable } 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 }