feat: integrate unified payment and wallet refunds
This commit is contained in:
@@ -2,9 +2,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/heqiapp/platforms/backend/worker/internal/config"
|
||||
@@ -14,8 +18,21 @@ import (
|
||||
func main() {
|
||||
config.New("PlatformWorker")
|
||||
impl.NewImpl()
|
||||
printer.Info("[BSM - PlatformWorker] Mock worker started; Redis Streams consumer is not enabled")
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go closeExpiredPayments(ctx)
|
||||
printer.Info("[BSM - PlatformWorker] payment timeout scheduler started")
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-quit
|
||||
cancel()
|
||||
}
|
||||
|
||||
func closeExpiredPayments(ctx context.Context) {
|
||||
ticker := time.NewTicker(time.Duration(config.Spec.PaymentAPI.IntervalSeconds) * time.Second); defer ticker.Stop()
|
||||
for { select { case <-ctx.Done(): return; case <-ticker.C:
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodPost, config.Spec.PaymentAPI.BaseURL+"/heqi/internal/v1/payment/close-expired", bytes.NewReader(nil)); if err != nil { continue }
|
||||
request.Header.Set("X-Heqi-Worker-Token", config.Spec.PaymentAPI.Token)
|
||||
response, err := http.DefaultClient.Do(request); if err == nil { _ = response.Body.Close() }
|
||||
} }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user