Skip to content

Commit

Permalink
change refresh in 00:00
Browse files Browse the repository at this point in the history
  • Loading branch information
KranjQ committed Dec 16, 2024
1 parent af32900 commit ce2c13d
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 129 deletions.
43 changes: 28 additions & 15 deletions cmd/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,11 @@ func main() {
fmt.Printf("Error starting server: %v\n", err)
}
}()
stopRefresh := make(chan bool)
refreshTicker := time.NewTicker(30 * time.Second)
defer refreshTicker.Stop()
//stopRefresh := make(chan bool)
//refreshTicker := time.NewTicker(30 * time.Second)
//defer refreshTicker.Stop()

go RefreshDailyLikes(ctx, paymentsClient, refreshTicker, stopRefresh)
go RefreshDailyLikes(ctx, paymentsClient)

stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
Expand All @@ -334,19 +334,32 @@ func main() {
fmt.Println("Сервер завершил работу.")
}

func RefreshDailyLikes(ctx context.Context, client grpcpayments.PaymentClient, ticker *time.Ticker, done chan bool) {
func RefreshDailyLikes(ctx context.Context, client grpcpayments.PaymentClient) {
//for {
// select {
// case <-done:
// fmt.Println("stop refresh")
// return
// case <-ticker.C:
// req := &grpcpayments.RefreshDailyLikeBalanceRequest{}
// _, err := client.RefreshDailyLikeBalance(ctx, req)
// if err != nil {
// fmt.Printf("Error stop refreshing daily likes: %v\n", err)
// return
// }
// }
//}
for {
select {
case <-done:
fmt.Println("stop refresh")
now := time.Now()
nextUpdate := time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, now.Location())

time.Sleep(time.Until(nextUpdate))

req := &grpcpayments.RefreshDailyLikeBalanceRequest{}
_, err := client.RefreshDailyLikeBalance(ctx, req)
if err != nil {
fmt.Printf("Error stop refreshing daily likes: %v\n", err)
return
case <-ticker.C:
req := &grpcpayments.RefreshDailyLikeBalanceRequest{}
_, err := client.RefreshDailyLikeBalance(ctx, req)
if err != nil {
fmt.Printf("Error stop refreshing daily likes: %v\n", err)
return
}
}
}
}
6 changes: 4 additions & 2 deletions internal/pkg/auth/delivery/http/signup/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) {
user.ID = int(id.UserId)

createBalancesRequest := &generatedPayments.CreateBalancesRequest{
UserID: id.UserId,
Amount: 3,
UserID: id.UserId,
MoneyAmount: 0,
DailyAmount: 10,
PurchasedAmount: 5,
}
_, err = h.paymentsClient.CreateBalances(ctx, createBalancesRequest)
if err != nil {
Expand Down
Loading

0 comments on commit ce2c13d

Please sign in to comment.