Add Wildberries product fetching and rate limiting functionality

This commit is contained in:
2025-07-04 13:30:50 +03:00
parent b48421e653
commit dc097c6fc8
67 changed files with 81355 additions and 110 deletions

View File

@@ -0,0 +1,39 @@
package server
import (
"github.com/hibiken/asynq"
"github.com/jackc/pgx/v5/pgxpool"
"sipro-mps/internal/config"
"sipro-mps/internal/tasks/types"
"sipro-mps/internal/tasks/wb"
)
type AsynqServer struct {
redisConfig *config.RedisConfig
dbpool *pgxpool.Pool
}
func NewAsynqServer(redisConfig *config.RedisConfig, dbpool *pgxpool.Pool) *AsynqServer {
return &AsynqServer{
redisConfig: redisConfig,
dbpool: dbpool,
}
}
func (s *AsynqServer) createMux() *asynq.ServeMux {
mux := asynq.NewServeMux()
// Register task handlers here
mux.Handle(types.TypeWbFetchProducts, &wb.FetchProductsProcessor{Dbpool: s.dbpool})
return mux
}
func (s *AsynqServer) Run() {
srv := asynq.NewServer(
asynq.RedisClientOpt{Addr: s.redisConfig.Addr, Password: s.redisConfig.Password},
asynq.Config{Concurrency: 10},
)
mux := s.createMux()
if err := srv.Run(mux); err != nil {
panic(err)
}
}