From 3113bc473dded76da11d74a83820ee79fef740d2 Mon Sep 17 00:00:00 2001 From: Daniel Cadenas Date: Wed, 21 Aug 2024 11:27:44 -0300 Subject: [PATCH] Correctly initialize follows puller --- Makefile | 4 ++-- cmd/notification-service/di/inject_pubsub.go | 5 +---- cmd/notification-service/di/wire.go | 7 ------- cmd/notification-service/di/wire_gen.go | 19 +++++++++++++------ docker-compose-integration.yml | 1 - service/app/follow_change_puller.go | 7 ++++--- 6 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 56502ce..ae53eaf 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,8 @@ test: .PHONY: recreate-emulator recreate-emulator: - sudo docker-compose -f ./docker-compose-integration.yml rm -f -s -v - sudo docker-compose -f ./docker-compose-integration.yml up -d + docker compose -f ./docker-compose-integration.yml rm -f -s -v + docker compose -f ./docker-compose-integration.yml up -d .PHONY: test-integration test-integration: diff --git a/cmd/notification-service/di/inject_pubsub.go b/cmd/notification-service/di/inject_pubsub.go index 40c45f8..f2b25ad 100644 --- a/cmd/notification-service/di/inject_pubsub.go +++ b/cmd/notification-service/di/inject_pubsub.go @@ -14,11 +14,8 @@ var pubsubSet = wire.NewSet( pubsub.NewReceivedEventPubSub, wire.Bind(new(app.ReceivedEventPublisher), new(*pubsub.ReceivedEventPubSub)), wire.Bind(new(app.ReceivedEventSubscriber), new(*pubsub.ReceivedEventPubSub)), -) - -var googlePubsubSet = wire.NewSet( - newExternalEventPublisher, newExternalFollowChangeSubscriber, + newExternalEventPublisher, ) func newExternalEventPublisher(config config.Config, logger watermill.LoggerAdapter) (app.ExternalEventPublisher, error) { diff --git a/cmd/notification-service/di/wire.go b/cmd/notification-service/di/wire.go index 6326748..4ec77fa 100644 --- a/cmd/notification-service/di/wire.go +++ b/cmd/notification-service/di/wire.go @@ -10,7 +10,6 @@ import ( "github.com/ThreeDotsLabs/watermill" "github.com/google/wire" "github.com/planetary-social/go-notification-service/service/adapters/apns" - "github.com/planetary-social/go-notification-service/service/adapters/mocks" "github.com/planetary-social/go-notification-service/service/app" "github.com/planetary-social/go-notification-service/service/config" "github.com/planetary-social/go-notification-service/service/domain/notifications" @@ -26,7 +25,6 @@ func BuildService(context.Context, config.Config) (Service, func(), error) { downloaderSet, generatorSet, pubsubSet, - googlePubsubSet, loggingSet, adaptersSet, followChangePullerSet, @@ -55,11 +53,6 @@ func BuildIntegrationService(context.Context, config.Config) (IntegrationService pubsubSet, loggingSet, integrationAdaptersSet, - - mocks.NewMockExternalEventPublisher, - mocks.NewMockExternalFollowChangeSubscriber, - wire.Bind(new(app.ExternalEventPublisher), new(*mocks.MockExternalEventPublisher)), - wire.Bind(new(app.ExternalFollowChangeSubscriber), new(*mocks.MockExternalFollowChangeSubscriber)), ) return IntegrationService{}, nil, nil } diff --git a/cmd/notification-service/di/wire_gen.go b/cmd/notification-service/di/wire_gen.go index ac21895..f5372ef 100644 --- a/cmd/notification-service/di/wire_gen.go +++ b/cmd/notification-service/di/wire_gen.go @@ -16,7 +16,6 @@ import ( "github.com/planetary-social/go-notification-service/service/adapters" "github.com/planetary-social/go-notification-service/service/adapters/apns" "github.com/planetary-social/go-notification-service/service/adapters/firestore" - "github.com/planetary-social/go-notification-service/service/adapters/mocks" "github.com/planetary-social/go-notification-service/service/adapters/prometheus" "github.com/planetary-social/go-notification-service/service/adapters/pubsub" "github.com/planetary-social/go-notification-service/service/app" @@ -154,8 +153,12 @@ func BuildIntegrationService(contextContext context.Context, configConfig config server := http.NewServer(configConfig, application, logger) metricsServer := http.NewMetricsServer(prometheusPrometheus, configConfig, logger) downloader := app.NewDownloader(memoryEventWasAlreadySavedCache, transactionProvider, receivedEventPubSub, logger, prometheusPrometheus) - mockExternalFollowChangeSubscriber := mocks.NewMockExternalFollowChangeSubscriber() - followChangePuller := app.NewFollowChangePuller(mockExternalFollowChangeSubscriber, logger, prometheusPrometheus) + externalFollowChangeSubscriber, err := newExternalFollowChangeSubscriber(configConfig, watermillAdapter) + if err != nil { + cleanup() + return IntegrationService{}, nil, err + } + followChangePuller := app.NewFollowChangePuller(externalFollowChangeSubscriber, logger, prometheusPrometheus) receivedEventSubscriber := memorypubsub.NewReceivedEventSubscriber(receivedEventPubSub, saveReceivedEventHandler, logger) subscriber, err := firestore.NewWatermillSubscriber(client, watermillAdapter) if err != nil { @@ -168,10 +171,14 @@ func BuildIntegrationService(contextContext context.Context, configConfig config cleanup() return IntegrationService{}, nil, err } - mockExternalEventPublisher := mocks.NewMockExternalEventPublisher() - processSavedEventHandler := app.NewProcessSavedEventHandler(transactionProvider, generator, apnsMock, logger, prometheusPrometheus, mockExternalEventPublisher) + externalEventPublisher, err := newExternalEventPublisher(configConfig, watermillAdapter) + if err != nil { + cleanup() + return IntegrationService{}, nil, err + } + processSavedEventHandler := app.NewProcessSavedEventHandler(transactionProvider, generator, apnsMock, logger, prometheusPrometheus, externalEventPublisher) eventSavedSubscriber := firestorepubsub.NewEventSavedSubscriber(subscriber, processSavedEventHandler, prometheusPrometheus, logger) - service := NewService(application, server, metricsServer, downloader, followChangePuller, receivedEventSubscriber, mockExternalFollowChangeSubscriber, eventSavedSubscriber, memoryEventWasAlreadySavedCache) + service := NewService(application, server, metricsServer, downloader, followChangePuller, receivedEventSubscriber, externalFollowChangeSubscriber, eventSavedSubscriber, memoryEventWasAlreadySavedCache) integrationService := IntegrationService{ Service: service, MockAPNS: apnsMock, diff --git a/docker-compose-integration.yml b/docker-compose-integration.yml index 7f17013..fcad93c 100644 --- a/docker-compose-integration.yml +++ b/docker-compose-integration.yml @@ -1,4 +1,3 @@ -version: "3.2" services: firestore_emulator: image: mtlynch/firestore-emulator diff --git a/service/app/follow_change_puller.go b/service/app/follow_change_puller.go index 1581230..6e43e01 100644 --- a/service/app/follow_change_puller.go +++ b/service/app/follow_change_puller.go @@ -20,9 +20,10 @@ func NewFollowChangePuller( metrics Metrics, ) *FollowChangePuller { return &FollowChangePuller{ - logger: logger.New("followChangePuller"), - metrics: metrics, - counter: 0, + externalFollowChangeSubscriber: externalFollowChangeSubscriber, + logger: logger.New("followChangePuller"), + metrics: metrics, + counter: 0, } }