-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (40 loc) · 1.43 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"async_worker/config"
"async_worker/internal"
"async_worker/internal/backgroundJobs/workers"
"async_worker/internal/drivers/rest"
jobprocessor "async_worker/internal/pkg/jobProcessor"
"async_worker/internal/pkg/jobProcessor/migrations"
someresource "async_worker/internal/someResource"
"context"
"github.com/gin-gonic/gin"
)
func main() {
ctx := context.Background()
cfg := config.NewConfig()
compositionRoot := internal.NewCompositionRoot(ctx, cfg)
backgroundJob, err := setupBackgroundJobProcessor(ctx, cfg, compositionRoot)
if err != nil {
panic(err)
}
defer backgroundJob.DbPool.Close()
router := gin.Default()
someResourceDependencies := someresource.NewSomeResourceDependencies(backgroundJob)
rest.BuildRoutes(router, someResourceDependencies)
router.Run(":8080")
}
func setupBackgroundJobProcessor(ctx context.Context, cfg *config.Config, deps *internal.CompositionRoot) (*jobprocessor.JobProcessorClient, error) {
err := migrations.PerformStartupRiverMigration(ctx, deps.DbPool)
if err != nil {
panic(err)
}
backgroundWorkersMgmnt := workers.NewBackgroundJobWorkers(deps.BackgroundWorkers)
workers.AddDefaultWorker(backgroundWorkersMgmnt)
workers.AddNewWorker(backgroundWorkersMgmnt, &workers.NewRequestWorker{})
jobProcessorClient, err := jobprocessor.NewJobProcessorClient(ctx, deps, cfg.BackgroundProcessorConfig)
if err != nil {
return nil, err
}
return jobProcessorClient, nil
}