{
  "repo": "tidbcloud/dataservices",
  "binary": "central_worker",
  "binary_path": "cmd/central_worker/main.go",
  "dependencies": {
    "CentralWorkerLifecycle.LoadConfigAndDatabase": {
      "infrastructure": {
        "filesystem": {
          "conditions": [
            "Always at startup"
          ],
          "operations": [
            {
              "operation": "READ FILE",
              "trigger": "Load config before sentry, database, eventbus, and worker startup",
              "conditions": [
                "Always"
              ],
              "implementation": "config.InitConfig(configPath)"
            }
          ]
        },
        "mysql": {
          "conditions": [
            "Always after config initialization succeeds"
          ],
          "operations": [
            {
              "operation": "CONNECT",
              "trigger": "Create the shared SQL connection used by eventbus and all workers",
              "conditions": [
                "config.InitConfig(configPath) succeeded"
              ],
              "implementation": "database.Connect(ctx, ...)"
            }
          ]
        }
      },
      "services": []
    },
    "CentralWorkerLifecycle.StartEventbus": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Only when local mode is disabled"
          ],
          "operations": [
            {
              "operation": "SUBSCRIBE / RUN LOOP",
              "trigger": "Start the dataservice_worker eventbus consumer",
              "conditions": [
                "!config.IsLocalMode()"
              ],
              "implementation": "eventbusStartup(ctx, sqlDB) -> eventbus.Init(\"dataservice_worker\", db).Run()"
            }
          ]
        }
      },
      "services": []
    },
    "CentralWorkerLifecycle.InitBackends": {
      "infrastructure": {
        "dynamodb": {
          "conditions": [
            "Always at startup"
          ],
          "operations": [
            {
              "operation": "CONNECT",
              "trigger": "Initialize the shared DynamoDB client consumed by private-link and cache helpers",
              "conditions": [
                "Always"
              ],
              "implementation": "ddb.Init(ctx, config)"
            }
          ]
        },
        "redis": {
          "conditions": [
            "Always at startup"
          ],
          "operations": [
            {
              "operation": "CONNECT",
              "trigger": "Initialize the shared Redis client before worker manager starts",
              "conditions": [
                "ddb.Init(ctx, config) succeeded"
              ],
              "implementation": "redisutil.NewRedisClient(ctx, config)"
            }
          ]
        }
      },
      "services": []
    },
    "CentralWorkerLifecycle.StartTracing": {
      "infrastructure": {},
      "services": []
    },
    "CentralWorkerLifecycle.StartMetricsServer": {
      "infrastructure": {
        "tcp": {
          "conditions": [
            "Always after backend initialization"
          ],
          "operations": [
            {
              "operation": "LISTEN",
              "trigger": "Expose worker Prometheus metrics on the dedicated metrics port",
              "conditions": [
                "Always"
              ],
              "implementation": "startupMetrics -> mEng.Run(\"0.0.0.0:\" + config.Global().ServerConf.MetricsPort)"
            }
          ]
        }
      },
      "services": []
    },
    "CentralWorkerLifecycle.StartWorkerManager": {
      "infrastructure": {
        "mysql": {
          "conditions": [
            "Only while worker manager is running"
          ],
          "operations": [
            {
              "operation": "SELECT / UPDATE",
              "trigger": "deployment worker polls waiting deployment logs and updates deploy status",
              "conditions": [
                "deployment_worker is enabled"
              ],
              "implementation": "repository.ListWaitingDeploymentLogs / UpdateDataAppDeploymentLogStatus / UpdateDataAppDeployLog"
            },
            {
              "operation": "SELECT / UPDATE",
              "trigger": "common task worker polls runnable tasks, updates status, retry count, and completion state",
              "conditions": [
                "commontask-worker is enabled"
              ],
              "implementation": "repository.SelectCommonTaskForRun / SelectCommonTaskByID / UpdateCommonTask"
            },
            {
              "operation": "SELECT / UPSERT / DELETE",
              "trigger": "etl worker loads endpoint/dataapp stats and persists hourly or daily rollups",
              "conditions": [
                "etl_worker runs every 10 minutes and the target hour has not already been processed"
              ],
              "implementation": "repository.CountEtlCombinedData / List*ByTimeRange / RecordEtlCombinedData / DeleteEtlCombinedData / RecordEtlActiveUser / RecordEtlEndpointRegion"
            }
          ]
        },
        "dynamodb": {
          "conditions": [
            "Only for private-link reconciliation"
          ],
          "operations": [
            {
              "operation": "GET / PUT / QUERY",
              "trigger": "private-link workers read and persist dedicated cluster endpoint state in DynamoDB",
              "conditions": [
                "privatelink_worker or CommonTaskTypePrivatelink is running"
              ],
              "implementation": "repository_ddb.GetUserClusterInfo / PutUserClusterInfo / ListUserClusterByIDs / QueryUserDedicatedClusterInfoWithPage"
            }
          ]
        }
      },
      "services": [
        {
          "name": "central-service",
          "target_repo": "tidbcloud/dataservices",
          "target_interface": "DeployDataApp|SyncSnapshotToGithub|DiscardDataAppDraft|TriggerDataAppDeployFromUI|PublishEndpointActionEvent",
          "operation_type": "local_service_call",
          "conditions": [
            "Only when deployment_worker or sample data common task reaches those states"
          ],
          "operations": [
            {
              "operation": "RUN DEPLOYMENT / PUBLISH FLOW",
              "trigger": "Deployment worker deploys snapshots and sample-data common task creates endpoints then triggers deployment",
              "conditions": [
                "deployment log selected for execution",
                "sample data common task advances through create-endpoint or deploy-endpoint states"
              ],
              "implementation": "service.DeployDataApp / SyncSnapshotToGithub / DiscardDataAppDraft / TriggerDataAppDeployFromUI / PublishEndpointActionEvent"
            }
          ]
        },
        {
          "name": "core-svc",
          "target_repo": "tidbcloud/core-svc",
          "target_interface": "GetCluster|GetClusterWithoutPermCheck|ListClusterByIdsWPC|ListClusterByOrgs|GetPrivateLinkService|CreatePrivateLinkEndpoint",
          "operation_type": "grpc_unary",
          "conditions": [
            "Only when common-task sample import, ETL region discovery, or private-link reconciliation needs cluster metadata"
          ],
          "operations": [
            {
              "operation": "LOOK UP CLUSTER / PRIVATE LINK STATE",
              "trigger": "Resolve cluster region, cluster ownership, or private-link service status",
              "conditions": [
                "sample data import needs cluster region",
                "etl needs org -> region mapping",
                "private-link workers need cluster inventory or service status"
              ],
              "implementation": "grpc.GetCluster / GetClusterWithoutPermCheck / ListClusterByIdsWPC / ListClusterByOrgs / GetPrivateLinkService / CreatePrivateLinkEndpoint"
            }
          ]
        },
        {
          "name": "account-acl",
          "target_repo": "tidbcloud/account",
          "target_interface": "GetJwtByUser",
          "operation_type": "grpc_unary",
          "conditions": [
            "Only in sample-data import common tasks"
          ],
          "operations": [
            {
              "operation": "GET DB JWT",
              "trigger": "Build the DB credential used to import sample data",
              "conditions": [
                "sample data common task has loaded the target cluster"
              ],
              "implementation": "grpc.GetJwtByUser(ctx, &acl.GetJwtByUserReq{...})"
            }
          ]
        },
        {
          "name": "regional-dataapi-gateway",
          "target_repo": "tidbcloud/dataservices",
          "target_interface": "CreateSession|ExecSql|CloseSession",
          "operation_type": "http_post",
          "conditions": [
            "Only in sample-data import common tasks"
          ],
          "operations": [
            {
              "operation": "SESSION + SQL EXECUTION",
              "trigger": "Import the Fortune500 sample dataset into the bound cluster",
              "conditions": [
                "sample data common task found a bound cluster",
                "cluster lookup and account JWT succeeded"
              ],
              "implementation": "http.CreateSession / ExecSql / CloseSession"
            }
          ]
        },
        {
          "name": "regional-dataapp-control",
          "target_repo": "tidbcloud/dataservices",
          "target_interface": "POST /inner/dataservice/apps/:app_id/dataapp-log/query|POST /inner/dataservice/projects/:project_id/clusters/:cluster_id/privatelink/create|POST /inner/dataservice/projects/:project_id/clusters/:cluster_id/privatelink/delete",
          "operation_type": "http_post",
          "conditions": [
            "ETL uses the log-query path; private-link flows use the create/delete paths"
          ],
          "operations": [
            {
              "operation": "QUERY REGIONAL LOGS",
              "trigger": "ETL iterates org-region pairs to collect endpoint execution logs",
              "conditions": [
                "etl worker has derived regions for an org"
              ],
              "implementation": "http.QueryDataAppLog(it.ctx, region, 0, req)"
            },
            {
              "operation": "CREATE / DELETE PRIVATE LINK",
              "trigger": "Private-link worker or common task reconciles regional endpoint state",
              "conditions": [
                "cluster is AWS dedicated and shadow-account eligible for create",
                "cluster deleted, unsupported, or not whitelisted for delete"
              ],
              "implementation": "http.CreatePrivateLink / http.DeletePrivateLink"
            }
          ]
        },
        {
          "name": "github",
          "target_repo": "external/github",
          "target_interface": "deployment snapshot sync",
          "operation_type": "git_sync",
          "conditions": [
            "Only when auto-deploy is enabled and deployment origin requires draft/GitHub synchronization"
          ],
          "operations": [
            {
              "operation": "SYNC SNAPSHOT",
              "trigger": "Keep UI draft and GitHub deployment source in sync after a successful deploy",
              "conditions": [
                "service.CheckDataAppEnableAutoDeploy(ctx, dataappID) is true",
                "deploy succeeded"
              ],
              "implementation": "SyncDeploymentToGithub -> service.SyncSnapshotToGithub / SyncDeploymentToUIDraft -> service.DiscardDataAppDraft"
            }
          ]
        }
      ]
    },
    "CentralWorkerLifecycle.ShutdownWorkerManager": {
      "infrastructure": {},
      "services": [],
      "conditions": [
        "Only after SIGINT or SIGTERM is received"
      ]
    },
    "HTTP GET /metrics": {
      "infrastructure": {},
      "services": []
    }
  }
}
