package tasks import ( "context" "git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service" "time" "github.com/gogf/gf/v2/frame/g" ) func init() { RegisterInnerTask("sync_traffic_usage_monthly", "SyncTrafficUsageMonthly") RegisterInnerTask("start_traffic_usage_full_sync", "StartTrafficUsageFullSync") RegisterInnerTask("start_traffic_usage_monthly_history", "StartTrafficUsageMonthlyHistory") } // SyncTrafficUsageMonthly publishes one command for Worker to execute the // previous-month usage history sync. Admin no longer scans cards itself: Worker // owns the scan, per-channel pacing, rounds, failure pool and replay. // // The timer name is unchanged so an existing sys_job row keeps working. func (t Task) SyncTrafficUsageMonthly() { t.runWithRedisJobLock(context.Background(), redisJobLockOptions{ InvokeTarget: "sync_traffic_usage_monthly", Period: -1, TTL: 30 * time.Minute, }, func(ctx context.Context) { if err := service.TrafficUsageMonthlySync().StartMonthlyHistory(ctx); err != nil { // The timer must fail visibly when the start command cannot be // published; Worker owns the actual full scan and overlap decision. g.Log().Errorf(ctx, "start monthly usage history full sync failed: %+v", err) } }) } func (t Task) StartTrafficUsageFullSync() { if err := service.TrafficUsageMonthlySync().StartMonthly(context.Background()); err != nil { // The timer should fail visibly when the start command cannot be published; // Worker owns the actual full scan and run-overlap decision. g.Log().Errorf(context.Background(), "start monthly usage full sync failed: %+v", err) } } // StartTrafficUsageMonthlyHistory is the explicit entry point for the monthly // history chain, kept separate from the legacy-named timer above so operators // can trigger a backfill without touching the scheduled row. func (t Task) StartTrafficUsageMonthlyHistory() { if err := service.TrafficUsageMonthlySync().StartMonthlyHistory(context.Background()); err != nil { g.Log().Errorf(context.Background(), "start monthly usage history full sync failed: %+v", err) } }