price pipeline
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
d7ec1fb355
commit
d9581d7f7e
16 changed files with 790 additions and 10 deletions
|
|
@ -11,7 +11,10 @@ import (
|
|||
"time"
|
||||
|
||||
"git.g3e.fr/H6N/account/internal/config"
|
||||
"git.g3e.fr/H6N/account/internal/pipeline"
|
||||
"git.g3e.fr/H6N/account/internal/scheduler"
|
||||
"git.g3e.fr/H6N/account/internal/server"
|
||||
"git.g3e.fr/H6N/account/internal/store"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
|
|
@ -20,7 +23,9 @@ func main() {
|
|||
|
||||
cfg := config.Load()
|
||||
|
||||
ctx := context.Background()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
pool, err := pgxpool.New(ctx, cfg.DatabaseURL)
|
||||
if err != nil {
|
||||
logger.Error("failed to create db pool", "error", err)
|
||||
|
|
@ -34,6 +39,25 @@ func main() {
|
|||
}
|
||||
logger.Info("database connected")
|
||||
|
||||
st := store.New(pool)
|
||||
pl := pipeline.New(st, pipeline.Config{
|
||||
OpenFIGIKey: cfg.OpenFIGIKey,
|
||||
CoinGeckoKey: cfg.CoinGeckoKey,
|
||||
}, logger)
|
||||
|
||||
sched := scheduler.New(logger)
|
||||
sched.Add(scheduler.Job{
|
||||
Name: "fetch-prices",
|
||||
Interval: cfg.PriceFetchInterval,
|
||||
Fn: pl.FetchAll,
|
||||
})
|
||||
sched.Add(scheduler.Job{
|
||||
Name: "clean-price-history",
|
||||
Interval: cfg.PriceCleanInterval,
|
||||
Fn: pl.CleanHistory,
|
||||
})
|
||||
sched.Start(ctx)
|
||||
|
||||
srv := server.New(cfg, pool, logger)
|
||||
|
||||
httpServer := &http.Server{
|
||||
|
|
@ -57,7 +81,8 @@ func main() {
|
|||
<-quit
|
||||
|
||||
logger.Info("shutting down")
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
cancel()
|
||||
shutdownCtx, stop := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer stop()
|
||||
httpServer.Shutdown(shutdownCtx)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue