mirror of
1
Fork 0

[chore] little startup tweaks (#2941)

* [chore] little startup tweaks

* go fmt
This commit is contained in:
tobi 2024-05-30 11:55:57 +02:00 committed by GitHub
parent 2fd69ec58b
commit 4db596b8b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 43 additions and 41 deletions

View File

@ -78,7 +78,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
// depending on what services were
// managed to be started.
state state.State
state = new(state.State)
route *router.Router
)
@ -137,7 +137,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
state.Caches.Start()
// Open connection to the database now caches started.
dbService, err := bundb.NewBunDBService(ctx, &state)
dbService, err := bundb.NewBunDBService(ctx, state)
if err != nil {
return fmt.Errorf("error creating dbservice: %s", err)
}
@ -177,14 +177,14 @@ var Start action.GTSAction = func(ctx context.Context) error {
})
// Build handlers used in later initializations.
mediaManager := media.NewManager(&state)
mediaManager := media.NewManager(state)
oauthServer := oauth.New(ctx, dbService)
typeConverter := typeutils.NewConverter(&state)
visFilter := visibility.NewFilter(&state)
spamFilter := spam.NewFilter(&state)
federatingDB := federatingdb.New(&state, typeConverter, visFilter, spamFilter)
transportController := transport.NewController(&state, federatingDB, &federation.Clock{}, client)
federator := federation.NewFederator(&state, federatingDB, transportController, typeConverter, visFilter, mediaManager)
typeConverter := typeutils.NewConverter(state)
visFilter := visibility.NewFilter(state)
spamFilter := spam.NewFilter(state)
federatingDB := federatingdb.New(state, typeConverter, visFilter, spamFilter)
transportController := transport.NewController(state, federatingDB, &federation.Clock{}, client)
federator := federation.NewFederator(state, federatingDB, transportController, typeConverter, visFilter, mediaManager)
// Decide whether to create a noop email
// sender (won't send emails) or a real one.
@ -205,18 +205,18 @@ var Start action.GTSAction = func(ctx context.Context) error {
// Initialize both home / list timelines.
state.Timelines.Home = timeline.NewManager(
tlprocessor.HomeTimelineGrab(&state),
tlprocessor.HomeTimelineFilter(&state, visFilter),
tlprocessor.HomeTimelineStatusPrepare(&state, typeConverter),
tlprocessor.HomeTimelineGrab(state),
tlprocessor.HomeTimelineFilter(state, visFilter),
tlprocessor.HomeTimelineStatusPrepare(state, typeConverter),
tlprocessor.SkipInsert(),
)
if err := state.Timelines.Home.Start(); err != nil {
return fmt.Errorf("error starting home timeline: %s", err)
}
state.Timelines.List = timeline.NewManager(
tlprocessor.ListTimelineGrab(&state),
tlprocessor.ListTimelineFilter(&state, visFilter),
tlprocessor.ListTimelineStatusPrepare(&state, typeConverter),
tlprocessor.ListTimelineGrab(state),
tlprocessor.ListTimelineFilter(state, visFilter),
tlprocessor.ListTimelineStatusPrepare(state, typeConverter),
tlprocessor.SkipInsert(),
)
if err := state.Timelines.List.Start(); err != nil {
@ -230,17 +230,19 @@ var Start action.GTSAction = func(ctx context.Context) error {
// Add a task to the scheduler to sweep caches.
// Frequency = 1 * minute
// Threshold = 60% capacity
_ = state.Workers.Scheduler.AddRecurring(
if !state.Workers.Scheduler.AddRecurring(
"@cachesweep", // id
time.Time{}, // start
time.Minute, // freq
func(context.Context, time.Time) {
state.Caches.Sweep(60)
},
)
) {
return fmt.Errorf("error scheduling cache sweep: %w", err)
}
// Create background cleaner.
cleaner := cleaner.New(&state)
cleaner := cleaner.New(state)
// Now schedule background cleaning tasks.
if err := cleaner.ScheduleJobs(); err != nil {
@ -255,7 +257,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
federator,
oauthServer,
mediaManager,
&state,
state,
emailSender,
)
@ -308,7 +310,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
// note: hooks adding ctx fields must be ABOVE
// the logger, otherwise won't be accessible.
middleware.Logger(config.GetLogClientIP()),
middleware.HeaderFilter(&state),
middleware.HeaderFilter(state),
middleware.UserAgent(),
middleware.CORS(),
middleware.ExtraHeaders(),
@ -366,7 +368,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
var (
authModule = api.NewAuth(dbService, processor, idp, routerSession, sessionName) // auth/oauth paths
clientModule = api.NewClient(&state, processor) // api client endpoints
clientModule = api.NewClient(state, processor) // api client endpoints
metricsModule = api.NewMetrics() // Metrics endpoints
healthModule = api.NewHealth(dbService.Ready) // Health check endpoints
fileserverModule = api.NewFileserver(processor) // fileserver endpoints

View File

@ -64,7 +64,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
// depending on what services were
// managed to be started.
state state.State
state = new(state.State)
route *router.Router
)
@ -85,7 +85,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
// Stop any currently running
// worker processes / scheduled
// tasks from being executed.
testrig.StopWorkers(&state)
testrig.StopWorkers(state)
if state.Timelines.Home != nil {
// Home timeline mgr was setup, ensure it gets stopped.
@ -130,7 +130,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
}
// Initialize caches and database
state.DB = testrig.NewTestDB(&state)
state.DB = testrig.NewTestDB(state)
// New test db inits caches so we don't need to do
// that twice, we can just start the initialized caches.
@ -156,11 +156,11 @@ var Start action.GTSAction = func(ctx context.Context) error {
testrig.StandardStorageSetup(state.Storage, "./testrig/media")
// Initialize workers.
testrig.StartNoopWorkers(&state)
defer testrig.StopWorkers(&state)
testrig.StartNoopWorkers(state)
defer testrig.StopWorkers(state)
// build backend handlers
transportController := testrig.NewTestTransportController(&state, testrig.NewMockHTTPClient(func(req *http.Request) (*http.Response, error) {
transportController := testrig.NewTestTransportController(state, testrig.NewMockHTTPClient(func(req *http.Request) (*http.Response, error) {
r := io.NopCloser(bytes.NewReader([]byte{}))
return &http.Response{
StatusCode: 200,
@ -170,34 +170,34 @@ var Start action.GTSAction = func(ctx context.Context) error {
},
}, nil
}, ""))
mediaManager := testrig.NewTestMediaManager(&state)
federator := testrig.NewTestFederator(&state, transportController, mediaManager)
mediaManager := testrig.NewTestMediaManager(state)
federator := testrig.NewTestFederator(state, transportController, mediaManager)
emailSender := testrig.NewEmailSender("./web/template/", nil)
typeConverter := typeutils.NewConverter(&state)
filter := visibility.NewFilter(&state)
typeConverter := typeutils.NewConverter(state)
filter := visibility.NewFilter(state)
// Initialize both home / list timelines.
state.Timelines.Home = timeline.NewManager(
tlprocessor.HomeTimelineGrab(&state),
tlprocessor.HomeTimelineFilter(&state, filter),
tlprocessor.HomeTimelineStatusPrepare(&state, typeConverter),
tlprocessor.HomeTimelineGrab(state),
tlprocessor.HomeTimelineFilter(state, filter),
tlprocessor.HomeTimelineStatusPrepare(state, typeConverter),
tlprocessor.SkipInsert(),
)
if err := state.Timelines.Home.Start(); err != nil {
return fmt.Errorf("error starting home timeline: %s", err)
}
state.Timelines.List = timeline.NewManager(
tlprocessor.ListTimelineGrab(&state),
tlprocessor.ListTimelineFilter(&state, filter),
tlprocessor.ListTimelineStatusPrepare(&state, typeConverter),
tlprocessor.ListTimelineGrab(state),
tlprocessor.ListTimelineFilter(state, filter),
tlprocessor.ListTimelineStatusPrepare(state, typeConverter),
tlprocessor.SkipInsert(),
)
if err := state.Timelines.List.Start(); err != nil {
return fmt.Errorf("error starting list timeline: %s", err)
}
processor := testrig.NewTestProcessor(&state, federator, emailSender, mediaManager)
processor := testrig.NewTestProcessor(state, federator, emailSender, mediaManager)
// Initialize metrics.
if err := metrics.Initialize(state.DB); err != nil {
@ -222,7 +222,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
middlewares = append(middlewares, []gin.HandlerFunc{
middleware.Logger(config.GetLogClientIP()),
middleware.HeaderFilter(&state),
middleware.HeaderFilter(state),
middleware.UserAgent(),
middleware.CORS(),
middleware.ExtraHeaders(),
@ -280,7 +280,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
var (
authModule = api.NewAuth(state.DB, processor, idp, routerSession, sessionName) // auth/oauth paths
clientModule = api.NewClient(&state, processor) // api client endpoints
clientModule = api.NewClient(state, processor) // api client endpoints
metricsModule = api.NewMetrics() // Metrics endpoints
healthModule = api.NewHealth(state.DB.Ready) // Health check endpoints
fileserverModule = api.NewFileserver(processor) // fileserver endpoints
@ -304,7 +304,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
webModule.Route(route)
// Create background cleaner.
cleaner := cleaner.New(&state)
cleaner := cleaner.New(state)
// Now schedule background cleaning tasks.
if err := cleaner.ScheduleJobs(); err != nil {