{
  "repo": "tidbcloud/billing",
  "binary": "worker",
  "binary_path": "cmd/worker/main.go",
  "dependencies": {
    "BillingWorkerLifecycle.LoadConfig": {
      "infrastructure": {
        "filesystem": {
          "conditions": [
            "Always at startup"
          ],
          "operations": [
            {
              "operation": "READ FILE",
              "trigger": "Load billing config before database, migrations, eventbus, and scheduler startup",
              "conditions": [
                "main() reached config.Init()"
              ],
              "implementation": "config.Init()"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerLifecycle.InitializeDatabase": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always after config initialization succeeds"
          ],
          "operations": [
            {
              "operation": "CONNECT",
              "trigger": "Create the shared primary and read-only billing database handles",
              "conditions": [
                "config.Init() succeeded"
              ],
              "implementation": "db.Initialize() -> initializeDB(getDBAuthConfig(false)); initializeDB(getReadOnlyAuthConfig())"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerLifecycle.RegisterEventHandlers": {
      "infrastructure": {},
      "services": [
        {
          "name": "billing-eventbus-runtime",
          "target_repo": "tidbcloud/billing",
          "target_interface": "plan/payment/marketing/notification event handlers",
          "operation_type": "local_registration",
          "conditions": [
            "Only when EnableEventbus is true"
          ],
          "operations": [
            {
              "operation": "REGISTER HANDLERS",
              "trigger": "Populate the shared eventbus handler registry before the run loop starts",
              "conditions": [
                "config.Get().GetBool(config.EnableEventbus)"
              ],
              "implementation": "api.RegisterEventHandler() -> RegisterEventHandler() on TenantPlanModel, InvoiceModel, PaymentModel, RechargeCreditsModel, SupportPlanModel, SpendLimitModel, BillingConfigEventHandler, NotificationModel, and marketing.RegisterMarketEventHandler()"
            }
          ]
        }
      ]
    },
    "BillingWorkerLifecycle.RunMigrations": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always after db.Initialize() succeeds"
          ],
          "operations": [
            {
              "operation": "CREATE / ALTER SCHEMA",
              "trigger": "Apply gormigrate schema and seed/data migrations on the billing database",
              "conditions": [
                "db.GetDB() is available"
              ],
              "implementation": "migrate.MigrateDB(db.GetDB(), true) -> gormigrate.New(...).InitSchema(...).Migrate()"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerLifecycle.InitializeCache": {
      "infrastructure": {
        "redis": {
          "conditions": [
            "Always at startup even if later cache lookups are feature-gated"
          ],
          "operations": [
            {
              "operation": "CONNECT",
              "trigger": "Build the shared Redis-backed cache client used by measure, invoice, and worker helpers",
              "conditions": [
                "main() reached cachehandler.Init()"
              ],
              "implementation": "cachehandler.Init() -> redis.NewClient(&redis.Options{Addr: RedisHost, DB: RedisDB})"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerLifecycle.InitializeRateLimiter": {
      "infrastructure": {},
      "services": []
    },
    "BillingWorkerLifecycle.InitializeWebIdentity": {
      "infrastructure": {},
      "services": []
    },
    "BillingWorkerLifecycle.InitializeLoggerAndSentry": {
      "infrastructure": {},
      "services": []
    },
    "BillingWorkerLifecycle.BuildHTTPServer": {
      "infrastructure": {},
      "services": []
    },
    "BillingWorkerLifecycle.RegisterPprof": {
      "infrastructure": {},
      "services": []
    },
    "BillingWorkerLifecycle.StartEventBus": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Only when EnableEventbus is true"
          ],
          "operations": [
            {
              "operation": "RUN LOOP",
              "trigger": "Start the billing eventbus consumer loop after handlers have been registered",
              "conditions": [
                "config.Get().GetBool(config.EnableEventbus)"
              ],
              "implementation": "eventbushandler.Get().Run() -> tieventbus.NewEventbus(...).Run()"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerLifecycle.InitializeMeasureSender": {
      "infrastructure": {},
      "services": [
        {
          "name": "measure-sqs",
          "target_repo": "tidbcloud/tiinf",
          "target_interface": "measure.MeasureSQSImpl.InitMeasureSqsHandler",
          "operation_type": "client_init",
          "conditions": [
            "Always at startup"
          ],
          "operations": [
            {
              "operation": "INITIALIZE SENDER",
              "trigger": "Set the default billing measure sender used by HTTP queue mode and some background metering flows",
              "conditions": [
                "main() reached sqsmeasurehandler.SetDefaultMeasureSender()"
              ],
              "implementation": "sqsmeasurehandler.SetDefaultMeasureSender() -> NewSQSMeasureSender() -> measure.MeasureSQSImpl.InitMeasureSqsHandler(config.Get().GetString(config.ENV), \"\")"
            }
          ]
        }
      ]
    },
    "BillingWorkerLifecycle.ConfigurePaymentHandler": {
      "infrastructure": {},
      "services": []
    },
    "BillingWorkerLifecycle.ConfigureMarketplaceHandler": {
      "infrastructure": {},
      "services": []
    },
    "BillingWorkerLifecycle.StartScheduler": {
      "infrastructure": {
        "scheduler": {
          "conditions": [
            "Always after startup initialization succeeds"
          ],
          "operations": [
            {
              "operation": "REGISTER JOBS",
              "trigger": "Create all configured gocron schedules before the worker listener starts",
              "conditions": [
                "workers.RunWorker(15 * time.Second) is reached"
              ],
              "implementation": "workers.RunWorker(maxStartDuration) -> wrapworker.NewWorker(conf.JobFunc, conf.Interval, conf.runInPersonalEnv)"
            },
            {
              "operation": "START ASYNC",
              "trigger": "Start each schedule with a randomized stagger to spread load",
              "conditions": [
                "worker schedule objects were created successfully"
              ],
              "implementation": "time.Sleep(maxStartDuration * rand.Float32()); s.StartAsync()"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerLifecycle.StartHTTPServer": {
      "infrastructure": {
        "tcp": {
          "conditions": [
            "Always after startup and scheduler initialization succeed"
          ],
          "operations": [
            {
              "operation": "LISTEN",
              "trigger": "Serve version, metrics, and pprof on the configured BillingServerPort",
              "conditions": [
                "engine.Run(fmt.Sprintf(\":%d\", config.Get().GetInt(config.BillingServerPort))) is reached"
              ],
              "implementation": "engine.Run(:BillingServerPort)"
            }
          ]
        }
      },
      "services": []
    },
    "HTTP GET /version": {
      "infrastructure": {},
      "services": []
    },
    "HTTP GET /metrics": {
      "infrastructure": {},
      "services": []
    },
    "HTTP GET /debug/pprof/*": {
      "infrastructure": {},
      "services": []
    },
    "HTTP POST /debug/pprof/symbol": {
      "infrastructure": {},
      "services": []
    },
    "BillingWorkerScheduler.CreateInvoiceWorker": {
      "infrastructure": {},
      "services": [
        {
          "name": "billing-worker-invoice",
          "target_repo": "tidbcloud/billing",
          "target_interface": "CreateInvoiceWorkerByTenant",
          "operation_type": "local_worker_call",
          "conditions": [
            "EnableInvoiceWorker is true"
          ],
          "operations": [
            {
              "operation": "FAN OUT BY TENANT",
              "trigger": "Run invoice generation across all payable tenants",
              "conditions": [
                "config.Get().GetBool(config.EnableInvoiceWorker)"
              ],
              "implementation": "CreateInvoiceWorkerFunc() -> paymentsub.PaymentModel.GetAllPayableTenantIDs() -> concurrency.RunInPoolWithIDs(..., CreateInvoiceWorkerByTenant, tenantIDs)"
            }
          ]
        },
        {
          "name": "account-central",
          "target_repo": "tidbcloud/account",
          "target_interface": "GetOrgByID|ListOrgs",
          "operation_type": "grpc_unary",
          "conditions": [
            "Only when CreateInvoiceWorkerByTenant runs and DBaaSCentralEnable is true"
          ],
          "operations": [
            {
              "operation": "LOOK UP TENANT",
              "trigger": "Load tenant state before generating and sending invoices",
              "conditions": [
                "CreateInvoiceWorkerByTenant(tenantID) is running",
                "config.Get().GetBool(config.DBaaSCentralEnable)"
              ],
              "implementation": "centralhandler.GetCentralHandler().GetTenant(tenantID)"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.SyncTenantPayableWorker": {
      "infrastructure": {},
      "services": [
        {
          "name": "billing-worker-payable",
          "target_repo": "tidbcloud/billing",
          "target_interface": "paymentsub.PaymentModel.SyncPayable",
          "operation_type": "local_worker_call",
          "conditions": [
            "EnableSyncPayableWorker is true"
          ],
          "operations": [
            {
              "operation": "SYNC PAYABLE",
              "trigger": "Refresh payable status for all tenants in parallel",
              "conditions": [
                "config.Get().GetBool(config.EnableSyncPayableWorker)"
              ],
              "implementation": "SyncTenantPayableWorker() -> concurrency.RunInPoolWithAllTenants(..., paymentModel.SyncPayable)"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.RemoveUnusedRawCosts": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always once the worker fires"
          ],
          "operations": [
            {
              "operation": "DELETE",
              "trigger": "Delete aged raw cost rows in the configured time window",
              "conditions": [
                "retry.Do(measureModel.RemoveUnusedRawCosts(...)) succeeds for the tenant"
              ],
              "implementation": "MeasureModel.RemoveUnusedRawCosts(dt, dt.Add(offset), tenantID)"
            }
          ]
        }
      },
      "services": [
        {
          "name": "account-central",
          "target_repo": "tidbcloud/account",
          "target_interface": "ListOrgs",
          "operation_type": "grpc_unary",
          "conditions": [
            "Only when RemoveUnusedRawCosts is invoked without explicit tenant IDs and DBaaSCentralEnable is true"
          ],
          "operations": [
            {
              "operation": "LIST TENANTS",
              "trigger": "Enumerate tenants for the raw-cost cleanup fan-out",
              "conditions": [
                "len(tenantIDs) == 0",
                "config.Get().GetBool(config.DBaaSCentralEnable)"
              ],
              "implementation": "centralhandler.GetCentralHandler().GetAllTenants()"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.RemoveUnusedCosts": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Only when EnableRemoveUnusedCosts is true"
          ],
          "operations": [
            {
              "operation": "DELETE",
              "trigger": "Delete aged merged cost rows before bills are calculated again",
              "conditions": [
                "config.Get().GetBool(config.EnableRemoveUnusedCosts)"
              ],
              "implementation": "MeasureModel.RemoveUnusedCosts(endTime, tenantID)"
            }
          ]
        }
      },
      "services": [
        {
          "name": "account-central",
          "target_repo": "tidbcloud/account",
          "target_interface": "ListOrgs",
          "operation_type": "grpc_unary",
          "conditions": [
            "Only when RemoveUnusedCosts is invoked without explicit tenant IDs and DBaaSCentralEnable is true"
          ],
          "operations": [
            {
              "operation": "LIST TENANTS",
              "trigger": "Enumerate tenants for merged-cost cleanup",
              "conditions": [
                "len(tenantIDs) == 0",
                "config.Get().GetBool(config.DBaaSCentralEnable)"
              ],
              "implementation": "centralhandler.GetCentralHandler().GetAllTenants()"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.MergeSmallCosts": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Only when EnableOfflineMerging is true"
          ],
          "operations": [
            {
              "operation": "SELECT / UPDATE",
              "trigger": "Merge small raw cost rows into a larger offline unit",
              "conditions": [
                "config.Get().GetBool(config.EnableOfflineMerging)"
              ],
              "implementation": "MeasureModel.MergeSmallUnits(dt, dt.Add(offset), tenantID)"
            }
          ]
        }
      },
      "services": [
        {
          "name": "account-central",
          "target_repo": "tidbcloud/account",
          "target_interface": "ListOrgs",
          "operation_type": "grpc_unary",
          "conditions": [
            "Only when MergeSmallCosts is invoked without explicit tenant IDs and DBaaSCentralEnable is true"
          ],
          "operations": [
            {
              "operation": "LIST TENANTS",
              "trigger": "Enumerate tenants for offline merge fan-out",
              "conditions": [
                "len(tenantIDs) == 0",
                "config.Get().GetBool(config.DBaaSCentralEnable)"
              ],
              "implementation": "centralhandler.GetCentralHandler().GetAllTenants()"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.SendSupportPlanMetering": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "SELECT / UPDATE / INSERT",
              "trigger": "Load bound support plans, adjust statuses, and emit support-plan metering rows",
              "conditions": [
                "SupportPlanWorkerByTenant(tenantID) is running"
              ],
              "implementation": "SyncSupportPlanStatusByTenant() + marketing.SupportPlanModel.SendNormalMetering / SendCommitmentMetering / SendReseller*"
            }
          ]
        }
      },
      "services": [
        {
          "name": "account-central",
          "target_repo": "tidbcloud/account",
          "target_interface": "GetOrgByID",
          "operation_type": "grpc_unary",
          "conditions": [
            "Only when DBaaSCentralEnable is true and a tenant has bound support plans"
          ],
          "operations": [
            {
              "operation": "LOOK UP TENANT",
              "trigger": "Decide MSP/reseller delay and metering branches",
              "conditions": [
                "SendSupportPlanMeteringByTenant(tenantID, now) is running",
                "config.Get().GetBool(config.DBaaSCentralEnable)"
              ],
              "implementation": "centralhandler.GetCentralHandler().GetTenant(tenantID)"
            }
          ]
        },
        {
          "name": "billing-measure-sender",
          "target_repo": "tidbcloud/tiinf",
          "target_interface": "MeasureSender.SendMeasure",
          "operation_type": "sqs_send",
          "conditions": [
            "Only when the selected support-plan metering model emits billing measures"
          ],
          "operations": [
            {
              "operation": "SEND MEASURE",
              "trigger": "Publish support-plan metering downstream through the configured measure sender",
              "conditions": [
                "marketing.SupportPlanModel.SendNormalMetering or SendCommitmentMetering reaches measure emission"
              ],
              "implementation": "support-plan model uses the global sqsmeasurehandler sender configured at startup"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.CloseExhaustedCreditsPackage": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "UPDATE",
              "trigger": "Close credits packages whose remaining balance is exhausted",
              "conditions": [
                "worker tick reached CloseExhaustedCreditsPackage"
              ],
              "implementation": "workers.CloseExhaustedCreditsPackage()"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerScheduler.CloseExpiredCreditsPackage": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "UPDATE",
              "trigger": "Close credits packages whose expiry date has passed",
              "conditions": [
                "worker tick reached CloseExpiredCreditsPackage"
              ],
              "implementation": "workers.CloseExpiredCreditsPackage()"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerScheduler.OpenNeedOpenCreditsPackage": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "UPDATE",
              "trigger": "Open credits packages whose activation window has started",
              "conditions": [
                "worker tick reached OpenNeedOpenCreditsPackage"
              ],
              "implementation": "workers.OpenNeedOpenCreditsPackage()"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerScheduler.CreateCostQuotaInvoice": {
      "infrastructure": {},
      "services": [
        {
          "name": "billing-cost-quota",
          "target_repo": "tidbcloud/billing",
          "target_interface": "CreateCostQuotaInvoiceByTenant",
          "operation_type": "local_worker_call",
          "conditions": [
            "EnableCreateCostQuotaInvoice is true"
          ],
          "operations": [
            {
              "operation": "FAN OUT BY TENANT",
              "trigger": "Generate Stripe-only cost-quota invoices for payable tenants",
              "conditions": [
                "config.Get().GetBool(config.EnableCreateCostQuotaInvoice)"
              ],
              "implementation": "CreateCostQuotaInvoice() -> concurrency.RunInPoolWithAllTenants(..., CreateCostQuotaInvoiceByTenant)"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.RefundForCreditCardVerify": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "SELECT / UPDATE",
              "trigger": "Drive credit-card verification refund state forward",
              "conditions": [
                "worker tick reached RefundForCreditCardVerify"
              ],
              "implementation": "workers.RefundForCreditCardVerify()"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerScheduler.RefundCheckForCreditCardVerify": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "SELECT",
              "trigger": "Poll refund state for credit-card verification records",
              "conditions": [
                "worker tick reached RefundCheckForCreditCardVerify"
              ],
              "implementation": "workers.RefundCheckForCreditCardVerify()"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerScheduler.ProgressTenantCreditRiskClose": {
      "infrastructure": {},
      "services": [
        {
          "name": "billing-credit-risk-close",
          "target_repo": "tidbcloud/billing",
          "target_interface": "creditriskcontrol.TenantCloseModel.ProcessTenantClose",
          "operation_type": "local_worker_call",
          "conditions": [
            "Always when there are running close records"
          ],
          "operations": [
            {
              "operation": "PROCESS CLOSE FLOW",
              "trigger": "Advance running tenant credit-risk-close workflows",
              "conditions": [
                "GetAllCreditCloseRunningTenantIDs() returns at least one tenant"
              ],
              "implementation": "ProgressTenantCreditRiskClose() -> concurrency.RunInPoolWithIDs(..., closeModel.ProcessTenantClose)"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.POCSyncCredits": {
      "infrastructure": {},
      "services": [
        {
          "name": "salesforce",
          "target_repo": "salesforce",
          "target_interface": "SyncPOCCreditsSalesforce",
          "operation_type": "http_post",
          "conditions": [
            "Only for active POC tenants returned by the plan model"
          ],
          "operations": [
            {
              "operation": "SYNC CREDITS",
              "trigger": "Push POC credit balances to Salesforce",
              "conditions": [
                "TenantPlanModel.GetAllPOCActiveTenantIDs() returned the tenant"
              ],
              "implementation": "TenantPlanModel.SyncPOCCreditsSalesforce(tenantID)"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.POCCleanup": {
      "infrastructure": {},
      "services": [
        {
          "name": "billing-plan-runtime",
          "target_repo": "tidbcloud/billing",
          "target_interface": "TenantPlanModel.POCCleanup",
          "operation_type": "local_worker_call",
          "conditions": [
            "Only for closing POC tenants"
          ],
          "operations": [
            {
              "operation": "CLEAN UP",
              "trigger": "Perform POC cleanup for closing tenants",
              "conditions": [
                "TenantPlanModel.GetAllPOCClosingTenantIDs() returned the tenant"
              ],
              "implementation": "TenantPlanModel.POCCleanup(tenantID)"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.POCCreditsEmailReminder": {
      "infrastructure": {},
      "services": [
        {
          "name": "billing-plan-runtime",
          "target_repo": "tidbcloud/billing",
          "target_interface": "TenantPlanModel.SendPOCReminderEmail",
          "operation_type": "local_worker_call",
          "conditions": [
            "Only for active POC tenants"
          ],
          "operations": [
            {
              "operation": "SEND REMINDER",
              "trigger": "Send reminder email for active POC credits",
              "conditions": [
                "TenantPlanModel.GetAllPOCActiveTenantIDs() returned the tenant"
              ],
              "implementation": "TenantPlanModel.SendPOCReminderEmail(tenantID)"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.CheckAllSpendLimit": {
      "infrastructure": {},
      "services": [
        {
          "name": "billing-spend-limit",
          "target_repo": "tidbcloud/billing",
          "target_interface": "CheckSpendLimitByTenant",
          "operation_type": "local_worker_call",
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "FAN OUT BY TENANT",
              "trigger": "Run spend-limit checks across all tenants",
              "conditions": [
                "CheckAllSpendLimit() is reached"
              ],
              "implementation": "CheckAllSpendLimit() -> concurrency.RunInPoolWithAllTenants(..., CheckSpendLimitByTenant)"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.RechargeCreditWorker": {
      "infrastructure": {},
      "services": [
        {
          "name": "billing-recharge",
          "target_repo": "tidbcloud/billing",
          "target_interface": "RechargeByTenant",
          "operation_type": "local_worker_call",
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "FAN OUT BY TENANT",
              "trigger": "Execute recharge plans for eligible tenants",
              "conditions": [
                "RechargeCreditWorker() is reached"
              ],
              "implementation": "RechargeCreditWorker() -> concurrency.RunInPoolWithAllTenants(..., RechargeByTenant)"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.ExpireCreditRechargePlan": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "UPDATE",
              "trigger": "Mark expired recharge plans as closed",
              "conditions": [
                "ExpireCreditRechargePlan() is reached"
              ],
              "implementation": "entity.NewRechargeCreditsPlanQuerySet(...).ExpiredDateLte(now).GetUpdater().SetClosedAt(&now).Update()"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerScheduler.InactiveTimeoutDiscountWorker": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "SELECT / UPDATE",
              "trigger": "Close inactive discounts that have timed out",
              "conditions": [
                "InactiveTimeoutDiscountWorker() is reached"
              ],
              "implementation": "discount.Model.InactiveTimeoutDiscount(...)"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerScheduler.InactiveTimeoutBindedPackagesWorker": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "SELECT / UPDATE",
              "trigger": "Close bound packages that have timed out",
              "conditions": [
                "InactiveTimeoutBindedPackagesWorker() is reached"
              ],
              "implementation": "billing.BindedPackageModel.InactiveTimeoutBindedPackages(...)"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerScheduler.CheckSupportPlanAccuracy": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Always when the worker fires and the check type branch matches"
          ],
          "operations": [
            {
              "operation": "SELECT",
              "trigger": "Load support plans, billing configs, and historical cost rows for the accuracy comparison",
              "conditions": [
                "CheckSupportPlanAccuracy() entered either checkHistory or checkPreviousMonth"
              ],
              "implementation": "SupportPlanModel.ListAllBindedSupportPlan(); BillingConfigModel.GetUseBillingConfigIDFromAllByTimeStampWithCache(...); CostExplorerModel.CalculateCost(...)"
            }
          ]
        }
      },
      "services": []
    },
    "BillingWorkerScheduler.SyncMarketOrgBills": {
      "infrastructure": {},
      "services": [
        {
          "name": "account-central",
          "target_repo": "tidbcloud/account",
          "target_interface": "ListOrgs",
          "operation_type": "grpc_unary",
          "conditions": [
            "Only when SyncMarketOrgBillsEnable is true and DBaaSCentralEnable is true"
          ],
          "operations": [
            {
              "operation": "LIST TENANTS",
              "trigger": "Build the tenant map before selecting marketplace-eligible organizations",
              "conditions": [
                "config.Get().GetBool(config.SyncMarketOrgBillsEnable)",
                "config.Get().GetBool(config.DBaaSCentralEnable)"
              ],
              "implementation": "centralhandler.GetCentralHandler().GetAllTenants()"
            }
          ]
        },
        {
          "name": "salesforce",
          "target_repo": "salesforce",
          "target_interface": "SyncMarketUserMonthBills",
          "operation_type": "http_post",
          "conditions": [
            "Only when the marketplace bill total is greater than zero"
          ],
          "operations": [
            {
              "operation": "SYNC MONTH BILL",
              "trigger": "Send marketplace tenant monthly bill totals to Salesforce",
              "conditions": [
                "DealAndSync(...) found positive InvoiceCostsCosts.CostPrice"
              ],
              "implementation": "salesforcehandler.Get().SyncMarketUserMonthBills(syncParam)"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.GenerateAWSDailyReportWorker": {
      "infrastructure": {},
      "services": [
        {
          "name": "billing-reconciliation",
          "target_repo": "tidbcloud/billing",
          "target_interface": "GenerateAWSDailyReportWorker",
          "operation_type": "local_worker_call",
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "RUN DAILY REPORT",
              "trigger": "Execute the AWS marketplace daily report job",
              "conditions": [
                "worker tick reached GenerateAWSDailyReportWorker"
              ],
              "implementation": "workers.GenerateAWSDailyReportWorker()"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.ReconciliationDailyWorker": {
      "infrastructure": {},
      "services": [
        {
          "name": "billing-reconciliation",
          "target_repo": "tidbcloud/billing",
          "target_interface": "ReconciliationDailyWorker",
          "operation_type": "local_worker_call",
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "RUN DAILY RECONCILIATION",
              "trigger": "Execute daily reconciliation checks",
              "conditions": [
                "worker tick reached ReconciliationDailyWorker"
              ],
              "implementation": "workers.ReconciliationDailyWorker()"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.ReconciliationMonthlyWorker": {
      "infrastructure": {},
      "services": [
        {
          "name": "billing-reconciliation",
          "target_repo": "tidbcloud/billing",
          "target_interface": "ReconciliationMonthlyWorker",
          "operation_type": "local_worker_call",
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "RUN MONTHLY RECONCILIATION",
              "trigger": "Execute monthly reconciliation checks",
              "conditions": [
                "worker tick reached ReconciliationMonthlyWorker"
              ],
              "implementation": "workers.ReconciliationMonthlyWorker()"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.BillingConfigScheduledExecution": {
      "infrastructure": {},
      "services": [
        {
          "name": "billing-config-runtime",
          "target_repo": "tidbcloud/billing",
          "target_interface": "BillingConfigScheduledExecution",
          "operation_type": "local_worker_call",
          "conditions": [
            "Always when the worker fires"
          ],
          "operations": [
            {
              "operation": "RUN SCHEDULED TRANSITIONS",
              "trigger": "Execute scheduled billing-config lifecycle transitions",
              "conditions": [
                "worker tick reached BillingConfigScheduledExecution"
              ],
              "implementation": "workers.BillingConfigScheduledExecution()"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.MarketplacePaymentWorker": {
      "infrastructure": {},
      "services": [
        {
          "name": "azure-marketplace-payment",
          "target_repo": "tidbcloud/billing",
          "target_interface": "paymentsub.PaymentModel.PaymentWorker",
          "operation_type": "local_worker_call",
          "conditions": [
            "Only when AZUREPaymentEnable is true"
          ],
          "operations": [
            {
              "operation": "RUN MARKETPLACE PAYMENT",
              "trigger": "Drive Azure marketplace payment workflow",
              "conditions": [
                "config.Get().GetBool(config.AZUREPaymentEnable)"
              ],
              "implementation": "MarketplacePaymentWorker() -> paymentModel.PaymentWorker(\"\")"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.NoTrafficDedicatedOrgCheckWorker": {
      "infrastructure": {},
      "services": [
        {
          "name": "infra-service",
          "target_repo": "tidbcloud/infra-api",
          "target_interface": "ListDedicatedClusters",
          "operation_type": "grpc_unary",
          "conditions": [
            "Always for each tenant being checked"
          ],
          "operations": [
            {
              "operation": "LIST DEDICATED CLUSTERS",
              "trigger": "Find dedicated clusters to inspect for missing traffic costs",
              "conditions": [
                "NoTrafficDedicatedOrgChecker(tenantID, billingMonth) is running"
              ],
              "implementation": "infrahandler.Get().ListDedicatedClusters(tenantID)"
            }
          ]
        },
        {
          "name": "billing-cost-explorer",
          "target_repo": "tidbcloud/billing",
          "target_interface": "CostTrendsWithMultiBillingConfigs",
          "operation_type": "local_service_call",
          "conditions": [
            "Only after dedicated clusters and billing configs were found"
          ],
          "operations": [
            {
              "operation": "QUERY COST TRENDS",
              "trigger": "Check whether a dedicated cluster has database cost but zero traffic cost",
              "conditions": [
                "ListDedicatedClusters returned at least one cluster"
              ],
              "implementation": "costexplorer.CostTrendsWithMultiBillingConfigs(...)"
            }
          ]
        }
      ]
    },
    "BillingWorkerScheduler.CostExplorerCacheWorker": {
      "infrastructure": {
        "redis": {
          "conditions": [
            "Only when CostExplorerCacheWorkerEnable is true and the cache list is non-empty"
          ],
          "operations": [
            {
              "operation": "SET CACHE",
              "trigger": "Warm monthly cost cache for configured tenant/billing-config pairs",
              "conditions": [
                "config.Get().GetBool(config.CostExplorerCacheWorkerEnable)",
                "len(config.Get().GetStringSlice(config.MonthlyBillsCacheList)) > 0"
              ],
              "implementation": "CostExplorerModel.SetMonthlyCostToCache(tenantID, billingConfigID, year, month)"
            }
          ]
        }
      },
      "services": []
    }
  }
}
