Add Wildberries product fetching and rate limiting functionality
This commit is contained in:
51
cmd/test/main.go
Normal file
51
cmd/test/main.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-faster/errors"
|
||||
"github.com/hibiken/asynq"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/redis/rueidis"
|
||||
"sipro-mps/internal/config"
|
||||
"sipro-mps/internal/redis"
|
||||
"sipro-mps/internal/tasks"
|
||||
)
|
||||
|
||||
func main() {
|
||||
godotenv.Load()
|
||||
ctx := context.Background()
|
||||
|
||||
redis.InitClient(ctx)
|
||||
c := *redis.Client
|
||||
key := fmt.Sprintf("wb:products:%d", "test")
|
||||
v, err := c.Do(ctx, c.B().Get().Key(key).Build()).ToString()
|
||||
if err != nil {
|
||||
if errors.As(err, &rueidis.Nil) {
|
||||
fmt.Println("Key does not exist in Redis:", key)
|
||||
return
|
||||
}
|
||||
}
|
||||
fmt.Println("Value from Redis:", v)
|
||||
return
|
||||
cfg, err := config.LoadConfig()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := asynq.NewClient(asynq.RedisClientOpt{Addr: cfg.Redis.Host + ":" + cfg.Redis.Port, Password: cfg.Redis.Password})
|
||||
defer func(client *asynq.Client) {
|
||||
err := client.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}(client)
|
||||
task, err := tasks.NewFetchProductsTask(1130)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
info, err := client.Enqueue(task)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
println("Task enqueued successfully:", info.ID, "with queue name:", info.Queue, "and payload size:", len(info.Payload), "bytes")
|
||||
}
|
||||
Reference in New Issue
Block a user