Add Wildberries product fetching and rate limiting functionality
This commit is contained in:
39
internal/tasks/server/server.go
Normal file
39
internal/tasks/server/server.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user