Files
platforms/backend/worker/cmd/main/main.go

39 lines
1.2 KiB
Go

// Worker 进程入口;保留独立扩缩和 Redis Streams 消费边界。
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"
"git.apinb.com/heqiapp/platforms/backend/worker/internal/impl"
)
func main() {
config.New("PlatformWorker")
impl.NewImpl()
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() }
} }
}