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() }
|
||||
} }
|
||||
}
|
||||
|
||||
@@ -6,4 +6,9 @@ Databases:
|
||||
- host=127.0.0.1 user=postgres password=change-me dbname=agent_dev port=5432 sslmode=disable TimeZone=Asia/Shanghai
|
||||
Cache: redis://default:change-me@127.0.0.1:6379/0
|
||||
OnMicroService: false
|
||||
|
||||
PaymentAPI:
|
||||
BaseURL: http://localhost:12426
|
||||
Token: change-me-payment-worker-token
|
||||
IntervalSeconds: 60
|
||||
SecretKey: change-me-to-a-random-string
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Package config 沿用 sample/server 的 BSM 运行配置与地址校验。
|
||||
// Package config 使用仓库统一的 BSM 运行配置与地址校验。
|
||||
package config
|
||||
|
||||
import (
|
||||
@@ -12,10 +12,18 @@ var Spec SrvConfig
|
||||
|
||||
// SrvConfig 保持与 API 进程相同的 BSM 配置结构。
|
||||
type SrvConfig struct {
|
||||
conf.Base `yaml:",inline"`
|
||||
Databases *conf.DBConf `yaml:"Databases"`
|
||||
Rpc map[string]conf.RpcConf `yaml:"Rpc"`
|
||||
Apm *conf.ApmConf `yaml:"APM"`
|
||||
conf.Base `yaml:",inline"`
|
||||
Databases *conf.DBConf `yaml:"Databases"`
|
||||
Rpc map[string]conf.RpcConf `yaml:"Rpc"`
|
||||
Apm *conf.ApmConf `yaml:"APM"`
|
||||
PaymentAPI PaymentAPIConfig `yaml:"PaymentAPI"`
|
||||
}
|
||||
|
||||
// PaymentAPIConfig 保存 Worker 调用支付内部动作所需的最小配置。
|
||||
type PaymentAPIConfig struct {
|
||||
BaseURL string `yaml:"BaseURL"`
|
||||
Token string `yaml:"Token"`
|
||||
IntervalSeconds int `yaml:"IntervalSeconds"`
|
||||
}
|
||||
|
||||
// New 初始化 Worker 配置。
|
||||
@@ -25,5 +33,8 @@ func New(srvKey string) {
|
||||
Spec.BindIP = conf.CheckIP(Spec.BindIP)
|
||||
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
|
||||
conf.NotNil(Spec.Service, Spec.Cache)
|
||||
if Spec.PaymentAPI.BaseURL == "" || Spec.PaymentAPI.Token == "" || Spec.PaymentAPI.IntervalSeconds <= 0 {
|
||||
panic("PaymentAPI configuration is required")
|
||||
}
|
||||
conf.PrintInfo(Spec.Addr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user