{
  "repo": "tidbcloud/billing",
  "binary": "worker",
  "binary_path": "cmd/worker/main.go",
  "surface_kind": "mixed_service",
  "type": "mixed_service",
  "extensions": {
    "notes": [
      "The worker binary does not expose the manual /worker/run or /worker/subtask/run handlers; those routes belong to cmd/server, while cmd/worker only serves /version, /metrics, and pprof on its HTTP listener.",
      "The primary runtime surface here is the scheduler: RunWorker registers 30 independent gocron jobs and starts them asynchronously with a randomized startup delay.",
      "cmd/worker also has startup-side effects that the previous scan flattened away: event-handler registration, gormigrate schema/data migrations, eventbus startup, and global payment / marketplace handler wiring."
    ]
  },
  "services": [
    {
      "name": "BillingWorkerLifecycle",
      "package": "cmd/worker",
      "methods": [
        {
          "name": "LoadConfig",
          "name_key": "BillingWorkerLifecycle.LoadConfig",
          "input": "process env + config files",
          "output": "global billing config initialized",
          "type": "local"
        },
        {
          "name": "InitializeDatabase",
          "name_key": "BillingWorkerLifecycle.InitializeDatabase",
          "input": "MySQL + read-only MySQL config",
          "output": "global primary and read-only GORM handles",
          "type": "local"
        },
        {
          "name": "RegisterEventHandlers",
          "name_key": "BillingWorkerLifecycle.RegisterEventHandlers",
          "input": "eventbus enable flag + model handler registrars",
          "output": "plan, invoice, payment, marketing, spend-limit, billing-config, and notification handlers registered on the shared eventbus",
          "type": "local"
        },
        {
          "name": "RunMigrations",
          "name_key": "BillingWorkerLifecycle.RunMigrations",
          "input": "global billing DB handle",
          "output": "gormigrate schema and data migrations applied",
          "type": "local"
        },
        {
          "name": "InitializeCache",
          "name_key": "BillingWorkerLifecycle.InitializeCache",
          "input": "EnableCache + RedisHost + RedisDB",
          "output": "shared cache handler initialized",
          "type": "local"
        },
        {
          "name": "InitializeRateLimiter",
          "name_key": "BillingWorkerLifecycle.InitializeRateLimiter",
          "input": "ratelimit config",
          "output": "shared rate limiter initialized",
          "type": "local"
        },
        {
          "name": "InitializeWebIdentity",
          "name_key": "BillingWorkerLifecycle.InitializeWebIdentity",
          "input": "AWS_WEB_IDENTITY_TOKEN_FILE + GCP workload identity env",
          "output": "GCP workload-identity auth preconditions validated",
          "type": "local"
        },
        {
          "name": "InitializeLoggerAndSentry",
          "name_key": "BillingWorkerLifecycle.InitializeLoggerAndSentry",
          "input": "EnableSentryLog + sentry DSN + log level",
          "output": "logger replaced and sentry hooked when enabled",
          "type": "local"
        },
        {
          "name": "BuildHTTPServer",
          "name_key": "BillingWorkerLifecycle.BuildHTTPServer",
          "input": "gin.Default()",
          "output": "worker HTTP engine with /version and /metrics",
          "type": "local"
        },
        {
          "name": "RegisterPprof",
          "name_key": "BillingWorkerLifecycle.RegisterPprof",
          "input": "worker gin engine",
          "output": "pprof endpoints mounted on the worker listener",
          "type": "local"
        },
        {
          "name": "StartEventBus",
          "name_key": "BillingWorkerLifecycle.StartEventBus",
          "input": "EnableEventbus + registered handlers",
          "output": "billing eventbus consumer loop running when enabled",
          "type": "background_worker"
        },
        {
          "name": "InitializeMeasureSender",
          "name_key": "BillingWorkerLifecycle.InitializeMeasureSender",
          "input": "ENV + measure SQS config",
          "output": "default SQS measure sender initialized",
          "type": "local"
        },
        {
          "name": "ConfigurePaymentHandler",
          "name_key": "BillingWorkerLifecycle.ConfigurePaymentHandler",
          "input": "impl.PaymentHandlerImpl{}",
          "output": "global payment handler set",
          "type": "local"
        },
        {
          "name": "ConfigureMarketplaceHandler",
          "name_key": "BillingWorkerLifecycle.ConfigureMarketplaceHandler",
          "input": "cloudimpl.MarketplaceHandlerImpl{}",
          "output": "global marketplace handler set",
          "type": "local"
        },
        {
          "name": "StartScheduler",
          "name_key": "BillingWorkerLifecycle.StartScheduler",
          "input": "30 configured worker jobs + random stagger up to 15s",
          "output": "gocron schedules started asynchronously",
          "type": "background_worker"
        },
        {
          "name": "StartHTTPServer",
          "name_key": "BillingWorkerLifecycle.StartHTTPServer",
          "input": "BillingServerPort",
          "output": "worker HTTP server serving version, metrics, and pprof routes",
          "type": "background_worker"
        }
      ]
    },
    {
      "name": "BillingWorkerHTTP",
      "package": "api",
      "type": "http",
      "methods": [
        {
          "name": "GET /version",
          "name_key": "HTTP GET /version",
          "path": "/version",
          "http_method": "GET",
          "input": "none",
          "output": "git hash payload",
          "type": "http"
        },
        {
          "name": "GET /metrics",
          "name_key": "HTTP GET /metrics",
          "path": "/metrics",
          "http_method": "GET",
          "input": "Prometheus scrape request",
          "output": "billing2 Prometheus metrics",
          "type": "http"
        }
      ]
    },
    {
      "name": "BillingWorkerPprofHTTP",
      "package": "pprof",
      "type": "http",
      "methods": [
        {
          "name": "GET /debug/pprof/*",
          "name_key": "HTTP GET /debug/pprof/*",
          "path": "/debug/pprof/*",
          "http_method": "GET",
          "input": "pprof profile path",
          "output": "Go pprof profile or index response",
          "type": "http"
        },
        {
          "name": "POST /debug/pprof/symbol",
          "name_key": "HTTP POST /debug/pprof/symbol",
          "path": "/debug/pprof/symbol",
          "http_method": "POST",
          "input": "pprof symbol body",
          "output": "resolved pprof symbols",
          "type": "http"
        }
      ]
    },
    {
      "name": "BillingWorkerScheduler",
      "package": "workers",
      "methods": [
        {
          "name": "CreateInvoiceWorker",
          "name_key": "BillingWorkerScheduler.CreateInvoiceWorker",
          "input": "InvoiceWorkerCheckInterval tick",
          "output": "invoice generation and send fan-out for payable tenants",
          "type": "background_worker"
        },
        {
          "name": "SyncTenantPayableWorker",
          "name_key": "BillingWorkerScheduler.SyncTenantPayableWorker",
          "input": "SyncPayableWorkerInterval tick",
          "output": "tenant payable status synced across all tenants",
          "type": "background_worker"
        },
        {
          "name": "RemoveUnusedRawCosts",
          "name_key": "BillingWorkerScheduler.RemoveUnusedRawCosts",
          "input": "RemoveUnusedCostsInterval tick",
          "output": "aged raw cost rows removed per tenant",
          "type": "background_worker"
        },
        {
          "name": "RemoveUnusedCosts",
          "name_key": "BillingWorkerScheduler.RemoveUnusedCosts",
          "input": "RemoveMergedCostsInterval tick",
          "output": "aged merged cost rows removed per tenant",
          "type": "background_worker"
        },
        {
          "name": "MergeSmallCosts",
          "name_key": "BillingWorkerScheduler.MergeSmallCosts",
          "input": "MergeSmallCostsInterval tick",
          "output": "small raw cost rows merged offline",
          "type": "background_worker"
        },
        {
          "name": "SendSupportPlanMetering",
          "name_key": "BillingWorkerScheduler.SendSupportPlanMetering",
          "input": "SupportPlanMeteringInterval tick",
          "output": "support-plan status sync plus normal, reseller, and commitment metering fan-out",
          "type": "background_worker"
        },
        {
          "name": "CloseExhaustedCreditsPackage",
          "name_key": "BillingWorkerScheduler.CloseExhaustedCreditsPackage",
          "input": "CreditsWorkerInterval tick",
          "output": "exhausted credits packages closed",
          "type": "background_worker"
        },
        {
          "name": "CloseExpiredCreditsPackage",
          "name_key": "BillingWorkerScheduler.CloseExpiredCreditsPackage",
          "input": "CreditsWorkerInterval tick",
          "output": "expired credits packages closed",
          "type": "background_worker"
        },
        {
          "name": "OpenNeedOpenCreditsPackage",
          "name_key": "BillingWorkerScheduler.OpenNeedOpenCreditsPackage",
          "input": "CreditsWorkerInterval tick",
          "output": "pending credits packages opened when they become active",
          "type": "background_worker"
        },
        {
          "name": "CreateCostQuotaInvoice",
          "name_key": "BillingWorkerScheduler.CreateCostQuotaInvoice",
          "input": "InvoiceWorkerCheckInterval tick",
          "output": "cost-quota invoices generated for Stripe payable tenants",
          "type": "background_worker"
        },
        {
          "name": "RefundForCreditCardVerify",
          "name_key": "BillingWorkerScheduler.RefundForCreditCardVerify",
          "input": "RefundWorkerInterval tick",
          "output": "credit-card verification refunds submitted",
          "type": "background_worker"
        },
        {
          "name": "RefundCheckForCreditCardVerify",
          "name_key": "BillingWorkerScheduler.RefundCheckForCreditCardVerify",
          "input": "RefundCheckWorkerInterval tick",
          "output": "credit-card verification refund state checked",
          "type": "background_worker"
        },
        {
          "name": "ProgressTenantCreditRiskClose",
          "name_key": "BillingWorkerScheduler.ProgressTenantCreditRiskClose",
          "input": "TenantCreditRiskCloseInterval tick",
          "output": "running tenant credit-close workflows progressed",
          "type": "background_worker"
        },
        {
          "name": "POCSyncCredits",
          "name_key": "BillingWorkerScheduler.POCSyncCredits",
          "input": "PlanWorkerInterval tick",
          "output": "POC credits synchronized to Salesforce",
          "type": "background_worker"
        },
        {
          "name": "POCCleanup",
          "name_key": "BillingWorkerScheduler.POCCleanup",
          "input": "PlanWorkerInterval tick",
          "output": "closing POC plans cleaned up",
          "type": "background_worker"
        },
        {
          "name": "POCCreditsEmailReminder",
          "name_key": "BillingWorkerScheduler.POCCreditsEmailReminder",
          "input": "PlanWorkerInterval tick",
          "output": "POC credits reminder emails sent",
          "type": "background_worker"
        },
        {
          "name": "CheckAllSpendLimit",
          "name_key": "BillingWorkerScheduler.CheckAllSpendLimit",
          "input": "CheckSpendLimitInterval tick",
          "output": "spend limits checked across all tenants",
          "type": "background_worker"
        },
        {
          "name": "RechargeCreditWorker",
          "name_key": "BillingWorkerScheduler.RechargeCreditWorker",
          "input": "RechargeCreditWorkerInterval tick",
          "output": "eligible tenant recharge plans executed",
          "type": "background_worker"
        },
        {
          "name": "ExpireCreditRechargePlan",
          "name_key": "BillingWorkerScheduler.ExpireCreditRechargePlan",
          "input": "RechargeCreditWorkerInterval tick",
          "output": "expired recharge plans marked closed",
          "type": "background_worker"
        },
        {
          "name": "InactiveTimeoutDiscountWorker",
          "name_key": "BillingWorkerScheduler.InactiveTimeoutDiscountWorker",
          "input": "InactiveDiscountWorkerInterval tick",
          "output": "timed-out discounts closed",
          "type": "background_worker"
        },
        {
          "name": "InactiveTimeoutBindedPackagesWorker",
          "name_key": "BillingWorkerScheduler.InactiveTimeoutBindedPackagesWorker",
          "input": "InactiveBindedPackageWorkerInterval tick",
          "output": "timed-out bound packages closed",
          "type": "background_worker"
        },
        {
          "name": "CheckSupportPlanAccuracy",
          "name_key": "BillingWorkerScheduler.CheckSupportPlanAccuracy",
          "input": "CheckSupportPlanAccuracyWorkerInterval tick",
          "output": "support-plan metering accuracy audit executed",
          "type": "background_worker"
        },
        {
          "name": "SyncMarketOrgBills",
          "name_key": "BillingWorkerScheduler.SyncMarketOrgBills",
          "input": "SyncMarketBillsWorkerInterval tick",
          "output": "marketplace org monthly bills synced to Salesforce when enabled",
          "type": "background_worker"
        },
        {
          "name": "GenerateAWSDailyReportWorker",
          "name_key": "BillingWorkerScheduler.GenerateAWSDailyReportWorker",
          "input": "AWSMarketplaceDailyReportGenerateInterval tick",
          "output": "AWS marketplace daily report generated",
          "type": "background_worker"
        },
        {
          "name": "ReconciliationDailyWorker",
          "name_key": "BillingWorkerScheduler.ReconciliationDailyWorker",
          "input": "ReconciliationDailyWorkerInterval tick",
          "output": "daily reconciliation checks executed",
          "type": "background_worker"
        },
        {
          "name": "ReconciliationMonthlyWorker",
          "name_key": "BillingWorkerScheduler.ReconciliationMonthlyWorker",
          "input": "ReconciliationMonthlyWorkerInterval tick",
          "output": "monthly reconciliation report executed",
          "type": "background_worker"
        },
        {
          "name": "BillingConfigScheduledExecution",
          "name_key": "BillingWorkerScheduler.BillingConfigScheduledExecution",
          "input": "BillingConfigWorkerInterval tick",
          "output": "scheduled billing-config transitions executed",
          "type": "background_worker"
        },
        {
          "name": "MarketplacePaymentWorker",
          "name_key": "BillingWorkerScheduler.MarketplacePaymentWorker",
          "input": "MarketplacePaymentInterval tick",
          "output": "Azure marketplace payment workflow executed",
          "type": "background_worker"
        },
        {
          "name": "NoTrafficDedicatedOrgCheckWorker",
          "name_key": "BillingWorkerScheduler.NoTrafficDedicatedOrgCheckWorker",
          "input": "NoTrafficCheckerRunInterval tick",
          "output": "no-traffic dedicated cluster audit executed",
          "type": "background_worker"
        },
        {
          "name": "CostExplorerCacheWorker",
          "name_key": "BillingWorkerScheduler.CostExplorerCacheWorker",
          "input": "CostExplorerCacheWorkerInterval tick",
          "output": "monthly cost explorer cache warmed for configured tenant/billing-config pairs",
          "type": "background_worker"
        }
      ]
    }
  ]
}
