this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'lebihae/partial-dryrun' into 'main'

feat(dry run): allow exempting some users from dry run

See merge request churros/notella!35

+71 -24
+20 -1
churros.go
··· 48 48 } 49 49 50 50 func (msg Message) CreateInDatabaseNotifications(groupId string, subs []Subscription) { 51 - if config.DryRunMode { 51 + if config.DryRunMode && len(config.DryRunExceptions) == 0 { 52 52 ll.Warn("dry run mode enabled, not creating notifications in database") 53 53 return 54 54 } 55 + 56 + subsFilter := func(sub Subscription) bool { return true } 57 + 58 + if len(config.DryRunExceptions) > 0 && config.DryRunMode { 59 + ll.Warn("dry run mode enabled: only creating notifications in database for %+v", config.DryRunExceptions) 60 + subsFilter = func(sub Subscription) bool { 61 + for _, username := range config.DryRunExceptions { 62 + if username == sub.Owner.Uid { 63 + return true 64 + } 65 + } 66 + return false 67 + } 68 + } 69 + 55 70 // Create sequentially: this is not something that has to be done fast, and parallelizing would swamp the database connections 56 71 for _, sub := range subs { 72 + if !subsFilter(sub) { 73 + continue 74 + } 75 + 57 76 prisma.Notification.CreateOne( 58 77 db.Notification.Subscription.Link( 59 78 db.NotificationSubscription.Endpoint.Equals(sub.Webpush.Endpoint),
+12 -11
config.go
··· 12 12 ) 13 13 14 14 type Configuration struct { 15 - ChurrosDatabaseURL string `env:"DATABASE_URL"` 16 - RedisURL string `env:"REDIS_URL"` 17 - NatsURL string `env:"NATS_URL" envDefault:"nats://localhost:4222"` 18 - VapidPublicKey string `env:"PUBLIC_VAPID_KEY"` 19 - VapidPrivateKey string `env:"VAPID_PRIVATE_KEY"` 20 - ContactEmail string `env:"CONTACT_EMAIL"` 21 - FirebaseServiceAccount string `env:"FIREBASE_SERVICE_ACCOUNT"` 22 - StartupScheduleRestoration string `env:"STARTUP_SCHEDULE_RESTORATION" envDefault:"enabled"` 23 - AppPackageId string `env:"APP_PACKAGE_ID" envDefault:"app.churros"` 24 - HealthCheckPort int `env:"HEALTH_CHECK_PORT" envDefault:"8080"` 25 - DryRunMode bool `env:"DRY_RUN" envDefault:"false"` 15 + ChurrosDatabaseURL string `env:"DATABASE_URL"` 16 + RedisURL string `env:"REDIS_URL"` 17 + NatsURL string `env:"NATS_URL" envDefault:"nats://localhost:4222"` 18 + VapidPublicKey string `env:"PUBLIC_VAPID_KEY"` 19 + VapidPrivateKey string `env:"VAPID_PRIVATE_KEY"` 20 + ContactEmail string `env:"CONTACT_EMAIL"` 21 + FirebaseServiceAccount string `env:"FIREBASE_SERVICE_ACCOUNT"` 22 + StartupScheduleRestoration string `env:"STARTUP_SCHEDULE_RESTORATION" envDefault:"enabled"` 23 + AppPackageId string `env:"APP_PACKAGE_ID" envDefault:"app.churros"` 24 + HealthCheckPort int `env:"HEALTH_CHECK_PORT" envDefault:"8080"` 25 + DryRunMode bool `env:"DRY_RUN" envDefault:"false"` 26 + DryRunExceptions []string `env:"DRY_RUN_EXCEPTIONS"` 26 27 } 27 28 28 29 func LoadConfiguration() (Configuration, error) {
+23 -7
firebase.go
··· 32 32 return fmt.Errorf("while initializing FCM client: %w", err) 33 33 } 34 34 35 + if config.DryRunMode && len(config.DryRunExceptions) == 0 { 36 + ll.Warn("dry run mode enabled, not sending FCM message to %d tokens", len(subs)) 37 + return nil 38 + } 39 + 35 40 message := msg.FirebaseMessage(groupId) 36 - tokens := make([]string, len(subs)) 37 - for i, sub := range subs { 38 - tokens[i] = sub.FirebaseToken() 41 + tokens := make([]string, 0, len(subs)) 42 + for _, sub := range subs { 43 + if config.DryRunMode { 44 + exempt := false 45 + for _, username := range config.DryRunExceptions { 46 + if username == sub.Owner.Uid { 47 + exempt = true 48 + } 49 + } 50 + if !exempt { 51 + continue 52 + } 53 + } 54 + tokens = append(tokens, sub.FirebaseToken()) 55 + } 56 + 57 + if config.DryRunMode { 58 + ll.Warn("dry run mode enabled, only sending FCM message to %d tokens (owned by %+v)", len(tokens), config.DryRunExceptions) 39 59 } 40 60 41 61 for _, tokensChunk := range chunkBy(tokens, MaxTokensPerRequest) { ··· 44 64 return 45 65 } 46 66 message.Tokens = tokens 47 - if config.DryRunMode { 48 - ll.Warn("dry run mode enabled, not sending FCM message to %d tokens", len(tokens)) 49 - return 50 - } 51 67 resp, err := fcm.SendEachForMulticast(firebaseCtx, &message) 52 68 if err != nil { 53 69 ll.ErrorDisplay("while sending FCM message", err)
+4 -2
server/main.go
··· 28 28 config, _ := notella.LoadConfiguration() 29 29 30 30 ll.Info("Server time is %s", time.Now().Format("2006-01-02 15:04:05 -07:00:00")) 31 - if config.DryRunMode { 31 + if config.DryRunMode && len(config.DryRunExceptions) > 0 { 32 + ll.Info("Running [bold]in dry run mode, [red]except for %+v[reset] with") 33 + } else if config.DryRunMode { 32 34 ll.Info("Running [bold]in dry run mode[reset] with") 33 35 } else { 34 - ll.Info("Running with config ") 36 + ll.Info("Running with config") 35 37 } 36 38 ll.Log("", "reset", "Schedule recovery: [bold][dim]at startup [reset][bold]%s[reset]", config.StartupScheduleRestoration) 37 39 ll.Log("", "reset", "contact email: [bold]%s[reset]", config.ContactEmail)
+1
typescript/configuration.ts
··· 3 3 CONTACT_EMAIL: string; 4 4 DATABASE_URL: string; 5 5 DRY_RUN: boolean; 6 + DRY_RUN_EXCEPTIONS: string[]; 6 7 FIREBASE_SERVICE_ACCOUNT: string; 7 8 HEALTH_CHECK_PORT: number; 8 9 NATS_URL: string;
+11 -3
webpush.go
··· 77 77 for _, sub := range subs { 78 78 go func(wg *sync.WaitGroup, sub Subscription) { 79 79 if config.DryRunMode { 80 - ll.Warn("dry run mode enabled, not sending webpush notification to %s", sub.Owner.Uid) 81 - wg.Done() 82 - return 80 + exempt := false 81 + for _, username := range config.DryRunExceptions { 82 + if username == sub.Owner.Uid { 83 + exempt = true 84 + } 85 + } 86 + if !exempt { 87 + ll.Warn("dry run mode enabled, not sending webpush notification to %s", sub.Owner.Uid) 88 + wg.Done() 89 + return 90 + } 83 91 } 84 92 resp, err := webpush.SendNotification(jsoned, &sub.Webpush, &webpush.Options{ 85 93 TTL: 30,