Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement proper backoff to handle arbitrarily failing messages #29

Merged
merged 10 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions cmd/crossposting-service/di/inject_adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ var sqliteAdaptersSet = wire.NewSet(

newAdaptersFactoryFn,

sqlite.NewMigrations,

wire.Struct(new(buildTransactionSqliteAdaptersDependencies), "*"),
)

Expand All @@ -34,8 +32,6 @@ var sqliteTestAdaptersSet = wire.NewSet(

newTestAdaptersFactoryFn,

sqlite.NewMigrations,

wire.Struct(new(buildTransactionSqliteAdaptersDependencies), "*"),
)

Expand Down
20 changes: 20 additions & 0 deletions cmd/crossposting-service/di/inject_migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package di

import (
"github.com/google/wire"
"github.com/planetary-social/nos-crossposting-service/migrations"
"github.com/planetary-social/nos-crossposting-service/service/adapters"
"github.com/planetary-social/nos-crossposting-service/service/adapters/sqlite"
)

var migrationsAdaptersSet = wire.NewSet(
sqlite.NewMigrations,
sqlite.NewMigrationFns,
migrations.NewRunner,

sqlite.NewMigrationsStorage,
wire.Bind(new(migrations.Storage), new(*sqlite.MigrationsStorage)),

adapters.NewLoggingMigrationsProgressCallback,
wire.Bind(new(migrations.ProgressCallback), new(*adapters.LoggingMigrationsProgressCallback)),
)
8 changes: 1 addition & 7 deletions cmd/crossposting-service/di/inject_pubsub.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package di

import (
watermillsql "github.com/ThreeDotsLabs/watermill-sql/v2/pkg/sql"
"github.com/google/wire"
"github.com/planetary-social/nos-crossposting-service/service/adapters/memorypubsub"
"github.com/planetary-social/nos-crossposting-service/service/adapters/sqlite"
Expand All @@ -16,17 +15,12 @@ var memoryPubsubSet = wire.NewSet(
)

var sqlitePubsubSet = wire.NewSet(
sqlite.NewSqliteSchema,
wire.Bind(new(watermillsql.SchemaAdapter), new(sqlite.SqliteSchema)),

sqlite.NewWatermillOffsetsAdapter,
sqlite.NewWatermillSubscriber,
sqlitepubsubport.NewTweetCreatedEventSubscriber,
sqlite.NewSubscriber,
sqlite.NewPubSub,
)

var sqliteTxPubsubSet = wire.NewSet(
sqlite.NewWatermillPublisher,
sqlite.NewPublisher,
wire.Bind(new(app.Publisher), new(*sqlite.Publisher)),
)
14 changes: 10 additions & 4 deletions cmd/crossposting-service/di/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/boreq/errors"
"github.com/hashicorp/go-multierror"
"github.com/planetary-social/nos-crossposting-service/service/adapters/sqlite"
"github.com/planetary-social/nos-crossposting-service/migrations"
"github.com/planetary-social/nos-crossposting-service/service/app"
"github.com/planetary-social/nos-crossposting-service/service/ports/http"
"github.com/planetary-social/nos-crossposting-service/service/ports/memorypubsub"
Expand All @@ -19,7 +19,9 @@ type Service struct {
downloader *app.Downloader
receivedEventSubscriber *memorypubsub.ReceivedEventSubscriber
tweetCreatedEventSubscriber *sqlitepubsub.TweetCreatedEventSubscriber
migrations *sqlite.Migrations
migrationsRunner *migrations.Runner
migrations migrations.Migrations
migrationsProgressCallback migrations.ProgressCallback
}

func NewService(
Expand All @@ -29,7 +31,9 @@ func NewService(
downloader *app.Downloader,
receivedEventSubscriber *memorypubsub.ReceivedEventSubscriber,
tweetCreatedEventSubscriber *sqlitepubsub.TweetCreatedEventSubscriber,
migrations *sqlite.Migrations,
migrationsRunner *migrations.Runner,
migrations migrations.Migrations,
migrationsProgressCallback migrations.ProgressCallback,
) Service {
return Service{
app: app,
Expand All @@ -38,7 +42,9 @@ func NewService(
downloader: downloader,
receivedEventSubscriber: receivedEventSubscriber,
tweetCreatedEventSubscriber: tweetCreatedEventSubscriber,
migrationsRunner: migrationsRunner,
migrations: migrations,
migrationsProgressCallback: migrationsProgressCallback,
}
}

Expand All @@ -47,7 +53,7 @@ func (s Service) App() app.Application {
}

func (s Service) ExecuteMigrations(ctx context.Context) error {
return s.migrations.Execute(ctx)
return s.migrationsRunner.Run(ctx, s.migrations, s.migrationsProgressCallback)
}

func (s Service) Run(ctx context.Context) error {
Expand Down
9 changes: 5 additions & 4 deletions cmd/crossposting-service/di/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"database/sql"
"testing"

"github.com/ThreeDotsLabs/watermill"
"github.com/google/wire"
"github.com/planetary-social/nos-crossposting-service/internal/fixtures"
"github.com/planetary-social/nos-crossposting-service/internal/logging"
Expand All @@ -31,6 +30,7 @@ func BuildService(context.Context, config.Config) (Service, func(), error) {
loggingSet,
adaptersSet,
tweetGeneratorSet,
migrationsAdaptersSet,
)
return Service{}, nil, nil
}
Expand All @@ -43,6 +43,7 @@ func BuildTestAdapters(context.Context, testing.TB) (sqlite.TestedItems, func(),
sqlitePubsubSet,
loggingSet,
newTestAdaptersConfig,
migrationsAdaptersSet,
)
return sqlite.TestedItems{}, nil, nil
}
Expand All @@ -61,13 +62,13 @@ func newTestAdaptersConfig(tb testing.TB) (config.Config, error) {
}

type buildTransactionSqliteAdaptersDependencies struct {
LoggerAdapter watermill.LoggerAdapter
Logger logging.Logger
}

func buildTransactionSqliteAdapters(*sql.DB, *sql.Tx, buildTransactionSqliteAdaptersDependencies) (app.Adapters, error) {
wire.Build(
wire.Struct(new(app.Adapters), "*"),
wire.FieldsOf(new(buildTransactionSqliteAdaptersDependencies), "LoggerAdapter"),
wire.FieldsOf(new(buildTransactionSqliteAdaptersDependencies), "Logger"),

sqliteTxAdaptersSet,
sqliteTxPubsubSet,
Expand All @@ -79,7 +80,7 @@ func buildTransactionSqliteAdapters(*sql.DB, *sql.Tx, buildTransactionSqliteAdap
func buildTestTransactionSqliteAdapters(*sql.DB, *sql.Tx, buildTransactionSqliteAdaptersDependencies) (sqlite.TestAdapters, error) {
wire.Build(
wire.Struct(new(sqlite.TestAdapters), "*"),
wire.FieldsOf(new(buildTransactionSqliteAdaptersDependencies), "LoggerAdapter"),
wire.FieldsOf(new(buildTransactionSqliteAdaptersDependencies), "Logger"),

sqliteTxAdaptersSet,
sqliteTxPubsubSet,
Expand Down
80 changes: 43 additions & 37 deletions cmd/crossposting-service/di/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.21

require (
github.com/ThreeDotsLabs/watermill v1.3.1
github.com/ThreeDotsLabs/watermill-sql/v2 v2.0.0
github.com/boreq/errors v0.1.0
github.com/boreq/rest v0.1.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1
Expand All @@ -19,7 +18,6 @@ require (
github.com/mattn/go-sqlite3 v1.14.17
github.com/nbd-wtf/go-nostr v0.18.10
github.com/oklog/ulid/v2 v2.1.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.16.0
github.com/rs/zerolog v1.29.1
github.com/sirupsen/logrus v1.9.3
Expand Down Expand Up @@ -58,6 +56,7 @@ require (
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/puzpuzpuz/xsync v1.5.2 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
Expand Down
Loading