@nosana/node 1.0.0-rc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -0
- package/dist/.env +7 -0
- package/dist/.env.dev +5 -0
- package/dist/.env.prd +4 -0
- package/dist/NodeManager/client/index.d.ts +4 -0
- package/dist/NodeManager/client/index.js +14 -0
- package/dist/NodeManager/configs/NodeConfigs.d.ts +14 -0
- package/dist/NodeManager/configs/NodeConfigs.js +32 -0
- package/dist/NodeManager/configs/__tests__/NodeConfigs.spec.d.ts +1 -0
- package/dist/NodeManager/configs/__tests__/NodeConfigs.spec.js +161 -0
- package/dist/NodeManager/configs/configs.d.ts +21 -0
- package/dist/NodeManager/configs/configs.js +23 -0
- package/dist/NodeManager/db/__tests__/index.spec.d.ts +1 -0
- package/dist/NodeManager/db/__tests__/index.spec.js +65 -0
- package/dist/NodeManager/db/index.d.ts +50 -0
- package/dist/NodeManager/db/index.js +64 -0
- package/dist/NodeManager/errors/NodeAlreadyActiveError.d.ts +3 -0
- package/dist/NodeManager/errors/NodeAlreadyActiveError.js +6 -0
- package/dist/NodeManager/index.d.ts +24 -0
- package/dist/NodeManager/index.js +317 -0
- package/dist/NodeManager/jobs/index.d.ts +6 -0
- package/dist/NodeManager/jobs/index.js +45 -0
- package/dist/NodeManager/monitoring/LogMonitoringRegistry.d.ts +9 -0
- package/dist/NodeManager/monitoring/LogMonitoringRegistry.js +23 -0
- package/dist/NodeManager/monitoring/log/NodeLog.d.ts +56 -0
- package/dist/NodeManager/monitoring/log/NodeLog.js +1357 -0
- package/dist/NodeManager/monitoring/log/console/ConsoleLogger.d.ts +20 -0
- package/dist/NodeManager/monitoring/log/console/ConsoleLogger.js +290 -0
- package/dist/NodeManager/monitoring/ping/PingHandler.d.ts +13 -0
- package/dist/NodeManager/monitoring/ping/PingHandler.js +68 -0
- package/dist/NodeManager/monitoring/proxy/loggingProxy.d.ts +15 -0
- package/dist/NodeManager/monitoring/proxy/loggingProxy.js +145 -0
- package/dist/NodeManager/monitoring/state/NodeState.d.ts +29 -0
- package/dist/NodeManager/monitoring/state/NodeState.js +680 -0
- package/dist/NodeManager/monitoring/state/classifyState.d.ts +14 -0
- package/dist/NodeManager/monitoring/state/classifyState.js +57 -0
- package/dist/NodeManager/monitoring/streaming/LogStreamer.d.ts +14 -0
- package/dist/NodeManager/monitoring/streaming/LogStreamer.js +58 -0
- package/dist/NodeManager/monitoring/streaming/StateStreamer.d.ts +15 -0
- package/dist/NodeManager/monitoring/streaming/StateStreamer.js +59 -0
- package/dist/NodeManager/node/Node.d.ts +44 -0
- package/dist/NodeManager/node/Node.js +321 -0
- package/dist/NodeManager/node/abort/NodeAbortController.d.ts +6 -0
- package/dist/NodeManager/node/abort/NodeAbortController.js +12 -0
- package/dist/NodeManager/node/abort/abortControllerSelector.d.ts +3 -0
- package/dist/NodeManager/node/abort/abortControllerSelector.js +13 -0
- package/dist/NodeManager/node/api/ApiEventEmitter.d.ts +8 -0
- package/dist/NodeManager/node/api/ApiEventEmitter.js +13 -0
- package/dist/NodeManager/node/api/ApiHandler.d.ts +28 -0
- package/dist/NodeManager/node/api/ApiHandler.js +193 -0
- package/dist/NodeManager/node/api/eventsource/index.d.ts +6 -0
- package/dist/NodeManager/node/api/eventsource/index.js +35 -0
- package/dist/NodeManager/node/api/middlewares/index.d.ts +5 -0
- package/dist/NodeManager/node/api/middlewares/index.js +7 -0
- package/dist/NodeManager/node/api/middlewares/rest/verifyBackendSignatureMiddleware.d.ts +3 -0
- package/dist/NodeManager/node/api/middlewares/rest/verifyBackendSignatureMiddleware.js +20 -0
- package/dist/NodeManager/node/api/middlewares/rest/verifyJobOwnerSignatureMiddleware.d.ts +5 -0
- package/dist/NodeManager/node/api/middlewares/rest/verifyJobOwnerSignatureMiddleware.js +28 -0
- package/dist/NodeManager/node/api/middlewares/ws/verifyWSJobOwnerSignatureMiddleware.d.ts +6 -0
- package/dist/NodeManager/node/api/middlewares/ws/verifyWSJobOwnerSignatureMiddleware.js +30 -0
- package/dist/NodeManager/node/api/middlewares/ws/verifyWSMiddleware.d.ts +6 -0
- package/dist/NodeManager/node/api/middlewares/ws/verifyWSMiddleware.js +20 -0
- package/dist/NodeManager/node/api/middlewares/ws/verifyWSNodeOrJobOwnerSignatureMiddleware.d.ts +6 -0
- package/dist/NodeManager/node/api/middlewares/ws/verifyWSNodeOrJobOwnerSignatureMiddleware.js +33 -0
- package/dist/NodeManager/node/api/routes/get/index.d.ts +6 -0
- package/dist/NodeManager/node/api/routes/get/index.js +6 -0
- package/dist/NodeManager/node/api/routes/get/job-definition.d.ts +5 -0
- package/dist/NodeManager/node/api/routes/get/job-definition.js +16 -0
- package/dist/NodeManager/node/api/routes/get/job-info/buildInfoObject.d.ts +17 -0
- package/dist/NodeManager/node/api/routes/get/job-info/buildInfoObject.js +15 -0
- package/dist/NodeManager/node/api/routes/get/job-info/job-info.d.ts +5 -0
- package/dist/NodeManager/node/api/routes/get/job-info/job-info.js +18 -0
- package/dist/NodeManager/node/api/routes/get/job-info/pollActiveJob.d.ts +6 -0
- package/dist/NodeManager/node/api/routes/get/job-info/pollActiveJob.js +42 -0
- package/dist/NodeManager/node/api/routes/get/job-operation-info.d.ts +28 -0
- package/dist/NodeManager/node/api/routes/get/job-operation-info.js +53 -0
- package/dist/NodeManager/node/api/routes/get/job-results.d.ts +5 -0
- package/dist/NodeManager/node/api/routes/get/job-results.js +15 -0
- package/dist/NodeManager/node/api/routes/get/node-info.d.ts +3 -0
- package/dist/NodeManager/node/api/routes/get/node-info.js +23 -0
- package/dist/NodeManager/node/api/routes/get/service-url.d.ts +5 -0
- package/dist/NodeManager/node/api/routes/get/service-url.js +27 -0
- package/dist/NodeManager/node/api/routes/index.d.ts +3 -0
- package/dist/NodeManager/node/api/routes/index.js +3 -0
- package/dist/NodeManager/node/api/routes/post/index.d.ts +4 -0
- package/dist/NodeManager/node/api/routes/post/index.js +4 -0
- package/dist/NodeManager/node/api/routes/post/job-definition.d.ts +6 -0
- package/dist/NodeManager/node/api/routes/post/job-definition.js +15 -0
- package/dist/NodeManager/node/api/routes/post/job-operation-actions.d.ts +24 -0
- package/dist/NodeManager/node/api/routes/post/job-operation-actions.js +79 -0
- package/dist/NodeManager/node/api/routes/post/node-validation.d.ts +4 -0
- package/dist/NodeManager/node/api/routes/post/node-validation.js +1783 -0
- package/dist/NodeManager/node/api/routes/post/service-stop.d.ts +5 -0
- package/dist/NodeManager/node/api/routes/post/service-stop.js +13 -0
- package/dist/NodeManager/node/api/routes/wss/index.d.ts +2 -0
- package/dist/NodeManager/node/api/routes/wss/index.js +2 -0
- package/dist/NodeManager/node/api/routes/wss/log.d.ts +14 -0
- package/dist/NodeManager/node/api/routes/wss/log.js +34 -0
- package/dist/NodeManager/node/api/routes/wss/status.d.ts +8 -0
- package/dist/NodeManager/node/api/routes/wss/status.js +11 -0
- package/dist/NodeManager/node/api/types/index.d.ts +12 -0
- package/dist/NodeManager/node/api/types/index.js +1 -0
- package/dist/NodeManager/node/balance/balanceHandler.d.ts +12 -0
- package/dist/NodeManager/node/balance/balanceHandler.js +52 -0
- package/dist/NodeManager/node/expiry/expiryHandler.d.ts +24 -0
- package/dist/NodeManager/node/expiry/expiryHandler.js +99 -0
- package/dist/NodeManager/node/grid/gridHandler.d.ts +19 -0
- package/dist/NodeManager/node/grid/gridHandler.js +168 -0
- package/dist/NodeManager/node/health/healthHandler.d.ts +16 -0
- package/dist/NodeManager/node/health/healthHandler.js +69 -0
- package/dist/NodeManager/node/job/JobRegistry.d.ts +14 -0
- package/dist/NodeManager/node/job/JobRegistry.js +48 -0
- package/dist/NodeManager/node/job/defination/JobDefinitionStrategy.d.ts +13 -0
- package/dist/NodeManager/node/job/defination/JobDefinitionStrategy.js +21 -0
- package/dist/NodeManager/node/job/defination/strategy/ApiJobDefinitionStrategy.d.ts +8 -0
- package/dist/NodeManager/node/job/defination/strategy/ApiJobDefinitionStrategy.js +40 -0
- package/dist/NodeManager/node/job/defination/strategy/ApiListenJobDefinitionStrategy.d.ts +9 -0
- package/dist/NodeManager/node/job/defination/strategy/ApiListenJobDefinitionStrategy.js +16 -0
- package/dist/NodeManager/node/job/defination/strategy/IpfsJobDefinitionStrategy.d.ts +7 -0
- package/dist/NodeManager/node/job/defination/strategy/IpfsJobDefinitionStrategy.js +13 -0
- package/dist/NodeManager/node/job/jobExternalUtil.d.ts +10 -0
- package/dist/NodeManager/node/job/jobExternalUtil.js +82 -0
- package/dist/NodeManager/node/job/jobHandler.d.ts +43 -0
- package/dist/NodeManager/node/job/jobHandler.js +193 -0
- package/dist/NodeManager/node/job/result/ResultReturnStrategy.d.ts +13 -0
- package/dist/NodeManager/node/job/result/ResultReturnStrategy.js +21 -0
- package/dist/NodeManager/node/job/result/startegy/ApiListenResultReturnStrategy.d.ts +8 -0
- package/dist/NodeManager/node/job/result/startegy/ApiListenResultReturnStrategy.js +22 -0
- package/dist/NodeManager/node/job/result/startegy/ApiResultReturnStrategy.d.ts +8 -0
- package/dist/NodeManager/node/job/result/startegy/ApiResultReturnStrategy.js +42 -0
- package/dist/NodeManager/node/key/keyHandler.d.ts +16 -0
- package/dist/NodeManager/node/key/keyHandler.js +74 -0
- package/dist/NodeManager/node/market/marketHandler.d.ts +30 -0
- package/dist/NodeManager/node/market/marketHandler.js +137 -0
- package/dist/NodeManager/node/register/index.d.ts +16 -0
- package/dist/NodeManager/node/register/index.js +88 -0
- package/dist/NodeManager/node/resource/definition/index.d.ts +2 -0
- package/dist/NodeManager/node/resource/definition/index.js +2 -0
- package/dist/NodeManager/node/resource/helpers/createHFArgs.d.ts +6 -0
- package/dist/NodeManager/node/resource/helpers/createHFArgs.js +26 -0
- package/dist/NodeManager/node/resource/helpers/createOllamaArgs.d.ts +2 -0
- package/dist/NodeManager/node/resource/helpers/createOllamaArgs.js +20 -0
- package/dist/NodeManager/node/resource/helpers/createResourceName.d.ts +2 -0
- package/dist/NodeManager/node/resource/helpers/createResourceName.js +18 -0
- package/dist/NodeManager/node/resource/helpers/createS3Args.d.ts +7 -0
- package/dist/NodeManager/node/resource/helpers/createS3Args.js +32 -0
- package/dist/NodeManager/node/resource/helpers/hasDockerVolume.d.ts +2 -0
- package/dist/NodeManager/node/resource/helpers/hasDockerVolume.js +3 -0
- package/dist/NodeManager/node/resource/helpers/hoursSunceDate.d.ts +1 -0
- package/dist/NodeManager/node/resource/helpers/hoursSunceDate.js +3 -0
- package/dist/NodeManager/node/resource/helpers/repoTagsContainsImage.d.ts +1 -0
- package/dist/NodeManager/node/resource/helpers/repoTagsContainsImage.js +13 -0
- package/dist/NodeManager/node/resource/image/imageManager.d.ts +13 -0
- package/dist/NodeManager/node/resource/image/imageManager.js +66 -0
- package/dist/NodeManager/node/resource/resourceManager.d.ts +21 -0
- package/dist/NodeManager/node/resource/resourceManager.js +57 -0
- package/dist/NodeManager/node/resource/volume/volumeManager.d.ts +20 -0
- package/dist/NodeManager/node/resource/volume/volumeManager.js +228 -0
- package/dist/NodeManager/node/run/runHandler.d.ts +18 -0
- package/dist/NodeManager/node/run/runHandler.js +139 -0
- package/dist/NodeManager/node/specs/specsHandler.d.ts +17 -0
- package/dist/NodeManager/node/specs/specsHandler.js +135 -0
- package/dist/NodeManager/node/specs/type.d.ts +15 -0
- package/dist/NodeManager/node/specs/type.js +1 -0
- package/dist/NodeManager/node/stake/StakeHandler.d.ts +22 -0
- package/dist/NodeManager/node/stake/StakeHandler.js +111 -0
- package/dist/NodeManager/node/task/TaskManager.d.ts +267 -0
- package/dist/NodeManager/node/task/TaskManager.js +480 -0
- package/dist/NodeManager/node/task/TaskManagerRegistry.d.ts +49 -0
- package/dist/NodeManager/node/task/TaskManagerRegistry.js +68 -0
- package/dist/NodeManager/node/task/executions/createDependencyMap.d.ts +18 -0
- package/dist/NodeManager/node/task/executions/createDependencyMap.js +32 -0
- package/dist/NodeManager/node/task/executions/createExecutionPlan.d.ts +14 -0
- package/dist/NodeManager/node/task/executions/createExecutionPlan.js +36 -0
- package/dist/NodeManager/node/task/executions/createOperationMap.d.ts +11 -0
- package/dist/NodeManager/node/task/executions/createOperationMap.js +34 -0
- package/dist/NodeManager/node/task/executions/validateExecutionPlan.d.ts +12 -0
- package/dist/NodeManager/node/task/executions/validateExecutionPlan.js +48 -0
- package/dist/NodeManager/node/task/globalStore/finalizeEnv.d.ts +2 -0
- package/dist/NodeManager/node/task/globalStore/finalizeEnv.js +30 -0
- package/dist/NodeManager/node/task/globalStore/getByPath.d.ts +2 -0
- package/dist/NodeManager/node/task/globalStore/getByPath.js +12 -0
- package/dist/NodeManager/node/task/globalStore/index.d.ts +9 -0
- package/dist/NodeManager/node/task/globalStore/index.js +9 -0
- package/dist/NodeManager/node/task/globalStore/interpolate.d.ts +2 -0
- package/dist/NodeManager/node/task/globalStore/interpolate.js +16 -0
- package/dist/NodeManager/node/task/globalStore/interpolateOperation.d.ts +3 -0
- package/dist/NodeManager/node/task/globalStore/interpolateOperation.js +221 -0
- package/dist/NodeManager/node/task/globalStore/resolveLiteralsInString.d.ts +2 -0
- package/dist/NodeManager/node/task/globalStore/resolveLiteralsInString.js +7 -0
- package/dist/NodeManager/node/task/globalStore/setDefaults.d.ts +4 -0
- package/dist/NodeManager/node/task/globalStore/setDefaults.js +65 -0
- package/dist/NodeManager/node/task/globalStore/setHost.d.ts +2 -0
- package/dist/NodeManager/node/task/globalStore/setHost.js +9 -0
- package/dist/NodeManager/node/task/globalStore/setResult.d.ts +2 -0
- package/dist/NodeManager/node/task/globalStore/setResult.js +10 -0
- package/dist/NodeManager/node/task/globalStore/setResults.d.ts +2 -0
- package/dist/NodeManager/node/task/globalStore/setResults.js +9 -0
- package/dist/NodeManager/node/task/globalStore/stanatizeArrays.d.ts +2 -0
- package/dist/NodeManager/node/task/globalStore/stanatizeArrays.js +14 -0
- package/dist/NodeManager/node/task/globalStore/transformCollections.d.ts +13 -0
- package/dist/NodeManager/node/task/globalStore/transformCollections.js +152 -0
- package/dist/NodeManager/node/task/helpers/createDefaultOpState.d.ts +2 -0
- package/dist/NodeManager/node/task/helpers/createDefaultOpState.js +20 -0
- package/dist/NodeManager/node/task/helpers/createInitialFlow.d.ts +8 -0
- package/dist/NodeManager/node/task/helpers/createInitialFlow.js +24 -0
- package/dist/NodeManager/node/task/loggers/logManager.d.ts +8 -0
- package/dist/NodeManager/node/task/loggers/logManager.js +54 -0
- package/dist/NodeManager/node/task/operations/getOperationsInfos.d.ts +6 -0
- package/dist/NodeManager/node/task/operations/getOperationsInfos.js +33 -0
- package/dist/NodeManager/node/task/operations/moveTaskManagerGroupOperation.d.ts +2 -0
- package/dist/NodeManager/node/task/operations/moveTaskManagerGroupOperation.js +65 -0
- package/dist/NodeManager/node/task/operations/restartTaskManagerGroupOperation.d.ts +10 -0
- package/dist/NodeManager/node/task/operations/restartTaskManagerGroupOperation.js +37 -0
- package/dist/NodeManager/node/task/operations/restartTaskManagerOperation.d.ts +14 -0
- package/dist/NodeManager/node/task/operations/restartTaskManagerOperation.js +117 -0
- package/dist/NodeManager/node/task/operations/runTaskManagerOperation.d.ts +21 -0
- package/dist/NodeManager/node/task/operations/runTaskManagerOperation.js +488 -0
- package/dist/NodeManager/node/task/operations/stopAllTaskManagerOperations.d.ts +21 -0
- package/dist/NodeManager/node/task/operations/stopAllTaskManagerOperations.js +54 -0
- package/dist/NodeManager/node/task/operations/stopTaskManagerGroupOperation.d.ts +10 -0
- package/dist/NodeManager/node/task/operations/stopTaskManagerGroupOperation.js +43 -0
- package/dist/NodeManager/node/task/operations/stopTaskManagerOperation.d.ts +14 -0
- package/dist/NodeManager/node/task/operations/stopTaskManagerOperation.js +137 -0
- package/dist/NodeManager/node/utils/convertFromBytes.d.ts +4 -0
- package/dist/NodeManager/node/utils/convertFromBytes.js +11 -0
- package/dist/NodeManager/node/utils/extractLogsAndResultsFromLogBuffer.d.ts +7 -0
- package/dist/NodeManager/node/utils/extractLogsAndResultsFromLogBuffer.js +34 -0
- package/dist/NodeManager/node/utils/extractResultsFromLogs.d.ts +18 -0
- package/dist/NodeManager/node/utils/extractResultsFromLogs.js +37 -0
- package/dist/NodeManager/node/utils/generateRandomId.d.ts +1 -0
- package/dist/NodeManager/node/utils/generateRandomId.js +3 -0
- package/dist/NodeManager/node/utils/multiProgressBarReporter.d.ts +16 -0
- package/dist/NodeManager/node/utils/multiProgressBarReporter.js +22 -0
- package/dist/NodeManager/node/utils/poll.d.ts +5 -0
- package/dist/NodeManager/node/utils/poll.js +25 -0
- package/dist/NodeManager/node/utils/progressBarReporter.d.ts +9 -0
- package/dist/NodeManager/node/utils/progressBarReporter.js +28 -0
- package/dist/NodeManager/provider/ContainerStateManager.d.ts +24 -0
- package/dist/NodeManager/provider/ContainerStateManager.js +122 -0
- package/dist/NodeManager/provider/ExposedPortHealthCheck.d.ts +29 -0
- package/dist/NodeManager/provider/ExposedPortHealthCheck.js +183 -0
- package/dist/NodeManager/provider/Provider.d.ts +70 -0
- package/dist/NodeManager/provider/Provider.js +457 -0
- package/dist/NodeManager/provider/__tests__/Provider.spec.d.ts +1 -0
- package/dist/NodeManager/provider/__tests__/Provider.spec.js +337 -0
- package/dist/NodeManager/provider/containerOrchestration/docker/dockerExtended/index.d.ts +6 -0
- package/dist/NodeManager/provider/containerOrchestration/docker/dockerExtended/index.js +45 -0
- package/dist/NodeManager/provider/containerOrchestration/docker/index.d.ts +43 -0
- package/dist/NodeManager/provider/containerOrchestration/docker/index.js +366 -0
- package/dist/NodeManager/provider/containerOrchestration/docker/utils/createServerObject.d.ts +5 -0
- package/dist/NodeManager/provider/containerOrchestration/docker/utils/createServerObject.js +15 -0
- package/dist/NodeManager/provider/containerOrchestration/docker/utils/deadline.d.ts +1 -0
- package/dist/NodeManager/provider/containerOrchestration/docker/utils/deadline.js +15 -0
- package/dist/NodeManager/provider/containerOrchestration/docker/utils/repoTagsContainsImage.d.ts +1 -0
- package/dist/NodeManager/provider/containerOrchestration/docker/utils/repoTagsContainsImage.js +13 -0
- package/dist/NodeManager/provider/containerOrchestration/interface.d.ts +53 -0
- package/dist/NodeManager/provider/containerOrchestration/interface.js +1 -0
- package/dist/NodeManager/provider/containerOrchestration/podman/index.d.ts +11 -0
- package/dist/NodeManager/provider/containerOrchestration/podman/index.js +69 -0
- package/dist/NodeManager/provider/containerOrchestration/podman/utils/createPodmanRunOptions.d.ts +103 -0
- package/dist/NodeManager/provider/containerOrchestration/podman/utils/createPodmanRunOptions.js +66 -0
- package/dist/NodeManager/provider/containerOrchestration/selectContainerOrchestration.d.ts +2 -0
- package/dist/NodeManager/provider/containerOrchestration/selectContainerOrchestration.js +11 -0
- package/dist/NodeManager/provider/types.d.ts +18 -0
- package/dist/NodeManager/provider/types.js +1 -0
- package/dist/NodeManager/provider/utils/parseBuffer.d.ts +4 -0
- package/dist/NodeManager/provider/utils/parseBuffer.js +19 -0
- package/dist/NodeManager/repository/NodeRepository.d.ts +53 -0
- package/dist/NodeManager/repository/NodeRepository.js +153 -0
- package/dist/NodeManager/sdk/index.d.ts +9 -0
- package/dist/NodeManager/sdk/index.js +146 -0
- package/dist/NodeManager/types/index.d.ts +27 -0
- package/dist/NodeManager/types/index.js +1 -0
- package/dist/NodeManager/utils/convertFromBytes.d.ts +4 -0
- package/dist/NodeManager/utils/convertFromBytes.js +11 -0
- package/dist/NodeManager/utils/expose-util.d.ts +14 -0
- package/dist/NodeManager/utils/expose-util.js +88 -0
- package/dist/NodeManager/utils/jobDefinitionParser.d.ts +12 -0
- package/dist/NodeManager/utils/jobDefinitionParser.js +31 -0
- package/dist/NodeManager/utils/ops-util.d.ts +3 -0
- package/dist/NodeManager/utils/ops-util.js +19 -0
- package/dist/NodeManager/utils/timeoutPromiseWrapper.d.ts +1 -0
- package/dist/NodeManager/utils/timeoutPromiseWrapper.js +27 -0
- package/dist/NodeManager/utils/utils.d.ts +39 -0
- package/dist/NodeManager/utils/utils.js +107 -0
- package/dist/NodeManager/utils/wslCheck.d.ts +14 -0
- package/dist/NodeManager/utils/wslCheck.js +54 -0
- package/dist/cli/address/__tests__/command.spec.d.ts +1 -0
- package/dist/cli/address/__tests__/command.spec.js +33 -0
- package/dist/cli/address/action.d.ts +4 -0
- package/dist/cli/address/action.js +4 -0
- package/dist/cli/address/command.d.ts +2 -0
- package/dist/cli/address/command.js +9 -0
- package/dist/cli/createNosanaCli.d.ts +2 -0
- package/dist/cli/createNosanaCli.js +32 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +16 -0
- package/dist/cli/node/__tests__/index.spec.d.ts +1 -0
- package/dist/cli/node/__tests__/index.spec.js +10 -0
- package/dist/cli/node/index.d.ts +5 -0
- package/dist/cli/node/index.js +12 -0
- package/dist/cli/node/prune/action.d.ts +4 -0
- package/dist/cli/node/prune/action.js +18 -0
- package/dist/cli/node/prune/command.d.ts +2 -0
- package/dist/cli/node/prune/command.js +10 -0
- package/dist/cli/node/run/__tests__/command.spec.d.ts +1 -0
- package/dist/cli/node/run/__tests__/command.spec.js +38 -0
- package/dist/cli/node/run/action.d.ts +3 -0
- package/dist/cli/node/run/action.js +82 -0
- package/dist/cli/node/run/command.d.ts +3 -0
- package/dist/cli/node/run/command.js +17 -0
- package/dist/cli/node/run/generateDeploymentEndpointsTable.d.ts +2 -0
- package/dist/cli/node/run/generateDeploymentEndpointsTable.js +45 -0
- package/dist/cli/node/start/__tests__/command.spec.d.ts +1 -0
- package/dist/cli/node/start/__tests__/command.spec.js +39 -0
- package/dist/cli/node/start/action.d.ts +4 -0
- package/dist/cli/node/start/action.js +48 -0
- package/dist/cli/node/start/command.d.ts +3 -0
- package/dist/cli/node/start/command.js +19 -0
- package/dist/cli/sharedOptions/--api.d.ts +2 -0
- package/dist/cli/sharedOptions/--api.js +2 -0
- package/dist/cli/sharedOptions/--format.d.ts +2 -0
- package/dist/cli/sharedOptions/--format.js +4 -0
- package/dist/cli/sharedOptions/--gpu.d.ts +2 -0
- package/dist/cli/sharedOptions/--gpu.js +12 -0
- package/dist/cli/sharedOptions/--network.d.ts +2 -0
- package/dist/cli/sharedOptions/--network.js +4 -0
- package/dist/cli/sharedOptions/--port.d.ts +2 -0
- package/dist/cli/sharedOptions/--port.js +2 -0
- package/dist/cli/sharedOptions/--rpc.d.ts +2 -0
- package/dist/cli/sharedOptions/--rpc.js +2 -0
- package/dist/cli/sharedOptions/--timeout.d.ts +2 -0
- package/dist/cli/sharedOptions/--timeout.js +12 -0
- package/dist/cli/sharedOptions/--verbose.d.ts +2 -0
- package/dist/cli/sharedOptions/--verbose.js +2 -0
- package/dist/cli/sharedOptions/--wallet.d.ts +2 -0
- package/dist/cli/sharedOptions/--wallet.js +2 -0
- package/dist/cli/sharedOptions/index.d.ts +7 -0
- package/dist/cli/sharedOptions/index.js +8 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/output-formatter/OutputFormatter.d.ts +61 -0
- package/dist/output-formatter/OutputFormatter.js +58 -0
- package/dist/output-formatter/OutputFormatterFactory.d.ts +4 -0
- package/dist/output-formatter/OutputFormatterFactory.js +18 -0
- package/dist/output-formatter/__mocks__/outputEvents.mock.d.ts +42 -0
- package/dist/output-formatter/__mocks__/outputEvents.mock.js +45 -0
- package/dist/output-formatter/__mocks__/outputFormatter.mock.d.ts +0 -0
- package/dist/output-formatter/__mocks__/outputFormatter.mock.js +21 -0
- package/dist/output-formatter/__tests__/OutputFormatter.spec.d.ts +1 -0
- package/dist/output-formatter/__tests__/OutputFormatter.spec.js +34 -0
- package/dist/output-formatter/__tests__/OutputFormatterFactory.spec.d.ts +1 -0
- package/dist/output-formatter/__tests__/OutputFormatterFactory.spec.js +26 -0
- package/dist/output-formatter/__tests__/outputFormatSelector.spec.d.ts +1 -0
- package/dist/output-formatter/__tests__/outputFormatSelector.spec.js +21 -0
- package/dist/output-formatter/json/JsonOutputEventHandlers.d.ts +8 -0
- package/dist/output-formatter/json/JsonOutputEventHandlers.js +191 -0
- package/dist/output-formatter/json/JsonOutputFormatter.d.ts +47 -0
- package/dist/output-formatter/json/JsonOutputFormatter.js +12 -0
- package/dist/output-formatter/json/__tests__/JsonOutputFormatter.spec.d.ts +1 -0
- package/dist/output-formatter/json/__tests__/JsonOutputFormatter.spec.js +36 -0
- package/dist/output-formatter/outputEvents.d.ts +213 -0
- package/dist/output-formatter/outputEvents.js +63 -0
- package/dist/output-formatter/outputFormatArgumentParser.d.ts +1 -0
- package/dist/output-formatter/outputFormatArgumentParser.js +10 -0
- package/dist/output-formatter/outputFormatSelector.d.ts +15 -0
- package/dist/output-formatter/outputFormatSelector.js +23 -0
- package/dist/output-formatter/text/TextOutputEventHandlers.d.ts +7 -0
- package/dist/output-formatter/text/TextOutputEventHandlers.js +128 -0
- package/dist/output-formatter/text/TextOutputFormatter.d.ts +6 -0
- package/dist/output-formatter/text/TextOutputFormatter.js +7 -0
- package/dist/output-formatter/text/VerboseTextOutputEventHandlers.d.ts +7 -0
- package/dist/output-formatter/text/VerboseTextOutputEventHandlers.js +138 -0
- package/dist/output-formatter/text/VerboseTextOutputFormatter.d.ts +6 -0
- package/dist/output-formatter/text/VerboseTextOutputFormatter.js +7 -0
- package/dist/output-formatter/text/__tests__/TextOutputFormatter.spec.d.ts +1 -0
- package/dist/output-formatter/text/__tests__/TextOutputFormatter.spec.js +25 -0
- package/dist/static/index.d.ts +7 -0
- package/dist/static/index.js +12 -0
- package/dist/version/index.d.ts +1 -0
- package/dist/version/index.js +47 -0
- package/npm-shrinkwrap.json +9928 -0
- package/package.json +102 -0
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { runTaskManagerOperation } from './operations/runTaskManagerOperation.js';
|
|
3
|
+
import { restartTaskManagerOperation } from './operations/restartTaskManagerOperation.js';
|
|
4
|
+
import { stopTaskManagerOperation } from './operations/stopTaskManagerOperation.js';
|
|
5
|
+
import { stopTaskManagerGroupOperations } from './operations/stopTaskManagerGroupOperation.js';
|
|
6
|
+
import { restartTaskManagerGroupOperations } from './operations/restartTaskManagerGroupOperation.js';
|
|
7
|
+
import { createOperationMap } from './executions/createOperationMap.js';
|
|
8
|
+
import { createExecutionPlan } from './executions/createExecutionPlan.js';
|
|
9
|
+
import { validateExecutionPlan } from './executions/validateExecutionPlan.js';
|
|
10
|
+
import { stopAllTaskManagerOperations } from './operations/stopAllTaskManagerOperations.js';
|
|
11
|
+
import { createInitialFlow } from './helpers/createInitialFlow.js';
|
|
12
|
+
import { createDependencyMap } from './executions/createDependencyMap.js';
|
|
13
|
+
import { getCurrentGroup, getCurrentGroupStatus, getGroupStatus, getOperationsStatus, getOperationStatus, } from './operations/getOperationsInfos.js';
|
|
14
|
+
import { addLog, getAllLogs, getLogsByGroup, getLogsByOp, subscribe, unsubscribe, } from './loggers/logManager.js';
|
|
15
|
+
import { moveTaskManagerGroupOperations } from './operations/moveTaskManagerGroupOperation.js';
|
|
16
|
+
import { setResult, setResults, setHost, setDefaults, rehydrateEndpointsForOperation, getByPath, resolveLiteralsInString, interpolate, interpolateOperation, transformCollections, } from './globalStore/index.js';
|
|
17
|
+
import { configs } from '../../configs/configs.js';
|
|
18
|
+
import { getSDK } from '../../sdk/index.js';
|
|
19
|
+
export const StopReasons = {
|
|
20
|
+
COMPLETED: 'completed',
|
|
21
|
+
EXPIRED: 'expired',
|
|
22
|
+
STOPPED: 'stopped',
|
|
23
|
+
QUIT: 'quit',
|
|
24
|
+
UNKNOWN: 'unknown',
|
|
25
|
+
RESTART: 'restart',
|
|
26
|
+
};
|
|
27
|
+
export const Statuses = {
|
|
28
|
+
SUCCESS: 'success',
|
|
29
|
+
STOPPED: 'stopped',
|
|
30
|
+
FAILED: 'failed',
|
|
31
|
+
};
|
|
32
|
+
export const OperationProgressStatuses = {
|
|
33
|
+
FINISHED: 'finished',
|
|
34
|
+
STOPPED: 'stopped',
|
|
35
|
+
FAILED: 'failed',
|
|
36
|
+
RUNNING: 'running',
|
|
37
|
+
RESTARTING: 'restarting',
|
|
38
|
+
STOPPING: 'stopping',
|
|
39
|
+
STARTING: 'starting',
|
|
40
|
+
WAITING: 'waiting',
|
|
41
|
+
PENDING: 'pending',
|
|
42
|
+
INIT: 'init',
|
|
43
|
+
};
|
|
44
|
+
export default class TaskManager {
|
|
45
|
+
constructor(provider, repository, job, project, definition) {
|
|
46
|
+
this.provider = provider;
|
|
47
|
+
this.repository = repository;
|
|
48
|
+
this.job = job;
|
|
49
|
+
this.project = project;
|
|
50
|
+
this.definition = definition;
|
|
51
|
+
/**
|
|
52
|
+
* The ordered execution plan built from the job definition.
|
|
53
|
+
* Each item represents a group of ops that run together horizontally.
|
|
54
|
+
*/
|
|
55
|
+
this.executionPlan = [];
|
|
56
|
+
/**
|
|
57
|
+
* this creates a map to assign the dependency
|
|
58
|
+
*/
|
|
59
|
+
this.dependecyMap = new Map();
|
|
60
|
+
/**
|
|
61
|
+
* A map for fast lookup of operations by their ID.
|
|
62
|
+
* Useful during validation and execution.
|
|
63
|
+
*/
|
|
64
|
+
this.opMap = new Map();
|
|
65
|
+
/**
|
|
66
|
+
* Global data store for all operations in a job definition.
|
|
67
|
+
*
|
|
68
|
+
* This allows operations to reference data produced by others using literals like:
|
|
69
|
+
* "%%ops.nginx-1.results.someKey%%"
|
|
70
|
+
* "%%ops.nginx-1.host%%"
|
|
71
|
+
*
|
|
72
|
+
* Supported keys:
|
|
73
|
+
* - result: Stores the output of an operation so it can be accessed later, even if it was unknown at the start of the job.
|
|
74
|
+
* - host: Stores the reachable host/URL of the operation. Since Docker container names are dynamic,
|
|
75
|
+
* this ensures other operations can communicate with it without needing to know the name in advance.
|
|
76
|
+
*/
|
|
77
|
+
this.globalOpStore = {};
|
|
78
|
+
/**
|
|
79
|
+
* Main controller to allow global cancellation of the entire task flow.
|
|
80
|
+
* All per-op controllers should eventually be tied to this as their parent,
|
|
81
|
+
* or fallback to this if no specific controller is assigned yet.
|
|
82
|
+
*/
|
|
83
|
+
this.mainAbortController = new AbortController();
|
|
84
|
+
/**
|
|
85
|
+
* Stores one AbortController per op.
|
|
86
|
+
* Used to signal cancellation to all ops in a group or individually if needed.
|
|
87
|
+
*/
|
|
88
|
+
this.abortControllerMap = new Map();
|
|
89
|
+
/**
|
|
90
|
+
* keeps track of all promises of the current running group
|
|
91
|
+
*/
|
|
92
|
+
this.currentGroupOperationsPromises = new Map();
|
|
93
|
+
/**
|
|
94
|
+
* this is to create concurrency control on the operations
|
|
95
|
+
*/
|
|
96
|
+
this.lockedOperations = new Map();
|
|
97
|
+
/**
|
|
98
|
+
* this is used to track the operations statuses
|
|
99
|
+
*/
|
|
100
|
+
this.operationStatus = new Map();
|
|
101
|
+
/**
|
|
102
|
+
* this is to track event emitter to emit events
|
|
103
|
+
*/
|
|
104
|
+
this.operationsEventEmitters = new Map();
|
|
105
|
+
/**
|
|
106
|
+
* save log buffer for streaming logs
|
|
107
|
+
*/
|
|
108
|
+
this.opLogBuffers = new Map();
|
|
109
|
+
/**
|
|
110
|
+
* this list of ws sub to the task managers events
|
|
111
|
+
*/
|
|
112
|
+
this.subscribers = new Set();
|
|
113
|
+
/**
|
|
114
|
+
* stores filters
|
|
115
|
+
*/
|
|
116
|
+
this.logMatchers = new Map();
|
|
117
|
+
this.TOTAL_LOGS_COUNT = 0;
|
|
118
|
+
/**
|
|
119
|
+
* Lifecycle status of the task manager.
|
|
120
|
+
* Can be 'init', 'running', 'stopped', or 'done'.
|
|
121
|
+
*/
|
|
122
|
+
this.status = 'init';
|
|
123
|
+
/**
|
|
124
|
+
* Event emitter for task- and op-level lifecycle events.
|
|
125
|
+
*/
|
|
126
|
+
this.events = new EventEmitter();
|
|
127
|
+
if (definition) {
|
|
128
|
+
this.operations = definition.ops;
|
|
129
|
+
}
|
|
130
|
+
this.runTaskManagerOperation = runTaskManagerOperation.bind(this);
|
|
131
|
+
this.restartTaskManagerOperation = restartTaskManagerOperation.bind(this);
|
|
132
|
+
this.stopTaskManagerOperation = stopTaskManagerOperation.bind(this);
|
|
133
|
+
this.stopTaskManagerGroupOperations =
|
|
134
|
+
stopTaskManagerGroupOperations.bind(this);
|
|
135
|
+
this.restartTaskManagerGroupOperations =
|
|
136
|
+
restartTaskManagerGroupOperations.bind(this);
|
|
137
|
+
this.moveTaskManagerGroupOperations =
|
|
138
|
+
moveTaskManagerGroupOperations.bind(this);
|
|
139
|
+
this.stopAllTaskManagerOperations = stopAllTaskManagerOperations.bind(this);
|
|
140
|
+
this.createOperationMap = createOperationMap.bind(this);
|
|
141
|
+
this.createExecutionPlan = createExecutionPlan.bind(this);
|
|
142
|
+
this.createDependencyMap = createDependencyMap.bind(this);
|
|
143
|
+
this.validateExecutionPlan = validateExecutionPlan.bind(this);
|
|
144
|
+
this.getOperationsStatus = getOperationsStatus.bind(this);
|
|
145
|
+
this.getOperationStatus = getOperationStatus.bind(this);
|
|
146
|
+
this.getCurrentGroup = getCurrentGroup.bind(this);
|
|
147
|
+
this.getCurrentGroupStatus = getCurrentGroupStatus.bind(this);
|
|
148
|
+
this.getGroupStatus = getGroupStatus.bind(this);
|
|
149
|
+
this.addlog = addLog.bind(this);
|
|
150
|
+
this.getLogsByOp = getLogsByOp.bind(this);
|
|
151
|
+
this.getLogsByGroup = getLogsByGroup.bind(this);
|
|
152
|
+
this.getAllLogs = getAllLogs.bind(this);
|
|
153
|
+
this.subscribe = subscribe.bind(this);
|
|
154
|
+
this.unsubscribe = unsubscribe.bind(this);
|
|
155
|
+
this.setResult = setResult.bind(this);
|
|
156
|
+
this.setResults = setResults.bind(this);
|
|
157
|
+
this.setHost = setHost.bind(this);
|
|
158
|
+
this.setDefaults = setDefaults.bind(this);
|
|
159
|
+
this.rehydrateEndpointsForOperation =
|
|
160
|
+
rehydrateEndpointsForOperation.bind(this);
|
|
161
|
+
this.getByPath = getByPath.bind(this);
|
|
162
|
+
this.resolveLiteralsInString = resolveLiteralsInString.bind(this);
|
|
163
|
+
this.interpolate = interpolate.bind(this);
|
|
164
|
+
this.interpolateOperation = interpolateOperation.bind(this);
|
|
165
|
+
this.transformCollections = transformCollections.bind(this);
|
|
166
|
+
const sdk = getSDK();
|
|
167
|
+
this.globalStore = {
|
|
168
|
+
job,
|
|
169
|
+
project,
|
|
170
|
+
frps_address: configs().frp.serverAddr,
|
|
171
|
+
host: sdk.solana.wallet.publicKey.toString(),
|
|
172
|
+
};
|
|
173
|
+
// Allow more listeners to account for many ops without warnings
|
|
174
|
+
this.events.setMaxListeners(100);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Returns the unified event emitter for this task manager.
|
|
178
|
+
*/
|
|
179
|
+
getEventsEmitter() {
|
|
180
|
+
return this.events;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Registers an op-level emitter and relays its relevant events to the
|
|
184
|
+
* task-level unified emitter. Also tracks the emitter in operationsEventEmitters.
|
|
185
|
+
*/
|
|
186
|
+
registerAndRelayOpEmitter(opId, emitter) {
|
|
187
|
+
const existing = this.operationsEventEmitters.get(opId);
|
|
188
|
+
if (existing && existing === emitter)
|
|
189
|
+
return;
|
|
190
|
+
const lifecycleEvents = new Set([
|
|
191
|
+
'start',
|
|
192
|
+
'exit',
|
|
193
|
+
'error',
|
|
194
|
+
'updateOpState',
|
|
195
|
+
'healthcheck:startup:success',
|
|
196
|
+
'flow:secrets-updated',
|
|
197
|
+
]);
|
|
198
|
+
const eventsToRegister = [...lifecycleEvents, 'log'];
|
|
199
|
+
if (existing && existing !== emitter) {
|
|
200
|
+
for (const eventName of eventsToRegister) {
|
|
201
|
+
existing.removeAllListeners(eventName);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
emitter.setMaxListeners(50);
|
|
205
|
+
const relay = (eventType) => (payload) => {
|
|
206
|
+
this.events.emit('op:event', { opId, type: eventType, payload });
|
|
207
|
+
// For events that impact job-info payload, also emit flow:updated
|
|
208
|
+
if (lifecycleEvents.has(eventType)) {
|
|
209
|
+
this.events.emit('flow:updated', {
|
|
210
|
+
jobId: this.job,
|
|
211
|
+
opId,
|
|
212
|
+
type: eventType,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
for (const eventName of eventsToRegister) {
|
|
217
|
+
emitter.on(eventName, relay(eventName));
|
|
218
|
+
}
|
|
219
|
+
this.operationsEventEmitters.set(opId, emitter);
|
|
220
|
+
this.events.emit('op:emitter-registered', { opId });
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Prepares the TaskManager for execution by performing all necessary setup steps.
|
|
224
|
+
*
|
|
225
|
+
* This method performs two key operations:
|
|
226
|
+
*
|
|
227
|
+
* `build()`:
|
|
228
|
+
* - Generates a map of all operations for fast lookup.
|
|
229
|
+
* - Creates the execution plan based on operation groups and dependencies.
|
|
230
|
+
* - Validates the structure of the plan to catch any misconfigurations early.
|
|
231
|
+
*
|
|
232
|
+
* `init()`:
|
|
233
|
+
* - Initializes the task's persistent flow state in the repository.
|
|
234
|
+
* - Skips initialization if the flow already exists (resumable/restartable design).
|
|
235
|
+
*
|
|
236
|
+
* Call this once before `start()` to ensure the task manager is fully ready.
|
|
237
|
+
*/
|
|
238
|
+
bootstrap() {
|
|
239
|
+
this.build(); // Set up opMap, executionPlan, and validate
|
|
240
|
+
this.init(); // Create initial flow in the repository if it doesn't already exist
|
|
241
|
+
// register all operations to init status
|
|
242
|
+
[...this.opMap.keys()].forEach((op) => this.operationStatus.set(op, OperationProgressStatuses.INIT));
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Starts the execution of the job by processing each group in the execution plan.
|
|
246
|
+
* Tracks the full lifecycle including flow state updates and dynamic operations.
|
|
247
|
+
*
|
|
248
|
+
* Execution Lifecycle:
|
|
249
|
+
* - If already started, returns the tracked lifecycle promise.
|
|
250
|
+
* - Sets status to 'running' and updates the repository with start time.
|
|
251
|
+
* - Iterates through execution groups and runs each op concurrently.
|
|
252
|
+
* - Uses a dynamic while-loop to ensure all ops (including restarts) finish before advancing.
|
|
253
|
+
* - After all groups finish, updates the flow state to 'success' or keeps previous status.
|
|
254
|
+
* - On any uncaught failure, marks the flow as 'failed' with end time.
|
|
255
|
+
*/
|
|
256
|
+
async start() {
|
|
257
|
+
// Return the lifecycle promise if already running
|
|
258
|
+
if (this.currentRunningStartPromise)
|
|
259
|
+
return this.currentRunningStartPromise;
|
|
260
|
+
// Track the entire execution lifecycle in one promise
|
|
261
|
+
this.currentRunningStartPromise = (async () => {
|
|
262
|
+
// Fetch existing flow to determine whether execution should continue
|
|
263
|
+
const flow = this.repository.getFlow(this.job);
|
|
264
|
+
try {
|
|
265
|
+
// If job already ended (either success or failure), no need to start again
|
|
266
|
+
// if (flow.state.endTime) return;
|
|
267
|
+
// Mark as running and update DB
|
|
268
|
+
this.status = 'running';
|
|
269
|
+
this.repository.updateflowState(this.job, {
|
|
270
|
+
status: this.status,
|
|
271
|
+
startTime: Date.now(),
|
|
272
|
+
});
|
|
273
|
+
this.events.emit('flow:updated', {
|
|
274
|
+
jobId: this.job,
|
|
275
|
+
type: 'status:start',
|
|
276
|
+
});
|
|
277
|
+
// update all operations status to pending since we have started
|
|
278
|
+
[...this.opMap.keys()].forEach((op) => this.operationStatus.set(op, OperationProgressStatuses.PENDING));
|
|
279
|
+
// Loop through execution plan, group by group
|
|
280
|
+
for (const p of this.executionPlan) {
|
|
281
|
+
this.currentGroup = p.group;
|
|
282
|
+
this.events.emit('flow:updated', {
|
|
283
|
+
jobId: this.job,
|
|
284
|
+
type: 'group:start',
|
|
285
|
+
group: this.currentGroup,
|
|
286
|
+
});
|
|
287
|
+
// Queue each operation in the group for execution
|
|
288
|
+
for (const id of p.ops) {
|
|
289
|
+
const dependencyContext = this.dependecyMap.get(id);
|
|
290
|
+
const dependencies = dependencyContext.dependencies || [];
|
|
291
|
+
const depsSatisfied = dependencies.length === 0 ||
|
|
292
|
+
dependencies.every((depId) => {
|
|
293
|
+
const depStatus = this.operationStatus.get(depId);
|
|
294
|
+
return (depStatus === OperationProgressStatuses.FINISHED ||
|
|
295
|
+
depStatus === OperationProgressStatuses.STOPPED);
|
|
296
|
+
});
|
|
297
|
+
if (depsSatisfied) {
|
|
298
|
+
this.operationStatus.set(id, OperationProgressStatuses.STARTING);
|
|
299
|
+
this.currentGroupOperationsPromises.set(id, this.trackGroupOperationPromise(id, this.setUpOperationFunc(flow, id, dependencyContext.dependents)));
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
this.operationStatus.set(id, OperationProgressStatuses.WAITING);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// push updated STARTING/WAITING statuses to listeners
|
|
306
|
+
this.events.emit('flow:updated', {
|
|
307
|
+
jobId: this.job,
|
|
308
|
+
type: 'group:schedule',
|
|
309
|
+
group: this.currentGroup,
|
|
310
|
+
});
|
|
311
|
+
try {
|
|
312
|
+
/**
|
|
313
|
+
* We use a `while` loop instead of a single `await Promise.all(...)` to handle dynamic group operations.
|
|
314
|
+
*
|
|
315
|
+
* Why:
|
|
316
|
+
* - During execution, new operations (like restarted ops) can be added to `currentGroupOperationsPromises`.
|
|
317
|
+
* - If we used a static `Promise.all(...)` outside the loop, it would only await the current snapshot,
|
|
318
|
+
* and any late-added promises wouldn't be awaited — leading to premature group advancement.
|
|
319
|
+
*
|
|
320
|
+
* This loop ensures:
|
|
321
|
+
* - We await all operations in the group, including those dynamically inserted (e.g. from restarts).
|
|
322
|
+
* - The group doesn't complete until all its tracked promises are settled and removed.
|
|
323
|
+
*/
|
|
324
|
+
while (this.currentGroupOperationsPromises.size > 0) {
|
|
325
|
+
await Promise.all([
|
|
326
|
+
...this.currentGroupOperationsPromises.values(),
|
|
327
|
+
]);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
finally {
|
|
331
|
+
// Reset group state after completion. successful or not
|
|
332
|
+
const finishedGroup = this.currentGroup;
|
|
333
|
+
this.currentGroup = undefined;
|
|
334
|
+
this.currentGroupOperationsPromises.clear();
|
|
335
|
+
this.events.emit('flow:updated', {
|
|
336
|
+
jobId: this.job,
|
|
337
|
+
type: 'group:end',
|
|
338
|
+
group: finishedGroup,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
// If status is still 'running', mark the job as successful
|
|
343
|
+
this.status = this.status === 'running' ? 'success' : this.status;
|
|
344
|
+
this.repository.updateflowState(this.job, {
|
|
345
|
+
status: this.status,
|
|
346
|
+
endTime: Date.now(),
|
|
347
|
+
secrets: {},
|
|
348
|
+
});
|
|
349
|
+
this.events.emit('flow:updated', {
|
|
350
|
+
jobId: this.job,
|
|
351
|
+
type: 'status:end',
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
// Any uncaught failure sets the flow to 'failed'
|
|
356
|
+
this.repository.updateflowState(this.job, {
|
|
357
|
+
status: 'failed',
|
|
358
|
+
endTime: Date.now(),
|
|
359
|
+
secrets: {},
|
|
360
|
+
});
|
|
361
|
+
this.events.emit('flow:updated', {
|
|
362
|
+
jobId: this.job,
|
|
363
|
+
type: 'status:failed',
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
finally {
|
|
367
|
+
// Do a total operation clean up where we go through all the opmap and clean all operations
|
|
368
|
+
const closingOperationPromises = [];
|
|
369
|
+
for (const op of this.opMap.values()) {
|
|
370
|
+
closingOperationPromises.push(this.provider.stopTaskManagerOperation(flow, op));
|
|
371
|
+
}
|
|
372
|
+
await Promise.all(closingOperationPromises);
|
|
373
|
+
}
|
|
374
|
+
})();
|
|
375
|
+
return this.currentRunningStartPromise;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Gracefully stops the task manager and all its operations.
|
|
379
|
+
*
|
|
380
|
+
* This method:
|
|
381
|
+
* - Immediately aborts all running operations by triggering the main abort controller.
|
|
382
|
+
* - Waits for the current `start()` flow to finish, including database updates.
|
|
383
|
+
* - Ensures `stop()` logic runs only once per job to prevent race conditions.
|
|
384
|
+
*
|
|
385
|
+
* Important:
|
|
386
|
+
* - `stopAllTaskManagerOperations()` is synchronous and triggers cancellation.
|
|
387
|
+
* - The actual cleanup and final state update (e.g., setting `endTime`) is handled
|
|
388
|
+
* by the `start()` method’s final logic.
|
|
389
|
+
*/
|
|
390
|
+
async stop(reason) {
|
|
391
|
+
const lockKey = `stop:${this.job}`;
|
|
392
|
+
// Ensure stop logic runs only once per job
|
|
393
|
+
if (this.lockedOperations.has(lockKey))
|
|
394
|
+
return;
|
|
395
|
+
this.lockedOperations.set(lockKey, reason);
|
|
396
|
+
try {
|
|
397
|
+
// Immediately abort all running operations
|
|
398
|
+
this.stopAllTaskManagerOperations(reason);
|
|
399
|
+
// Wait for the ongoing start logic to gracefully complete
|
|
400
|
+
if (this.currentRunningStartPromise) {
|
|
401
|
+
try {
|
|
402
|
+
await this.currentRunningStartPromise;
|
|
403
|
+
}
|
|
404
|
+
catch {
|
|
405
|
+
// We ignore start errors during shutdown — cleanup should proceed regardless
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
finally {
|
|
410
|
+
// Cleanup the lock regardless of outcome
|
|
411
|
+
this.lockedOperations.delete(lockKey);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
setUpOperationFunc(flow, id, dependent) {
|
|
415
|
+
const op = this.opMap.get(id);
|
|
416
|
+
if (!op) {
|
|
417
|
+
throw new Error(`Invalid Op id: ${id}`);
|
|
418
|
+
}
|
|
419
|
+
return this.runTaskManagerOperation(flow, op, dependent);
|
|
420
|
+
}
|
|
421
|
+
trackGroupOperationPromise(opId, promise) {
|
|
422
|
+
this.currentGroupOperationsPromises.set(opId, promise);
|
|
423
|
+
promise.finally(() => {
|
|
424
|
+
this.currentGroupOperationsPromises.delete(opId);
|
|
425
|
+
for (const [nextOpId, { execution }] of this.opMap) {
|
|
426
|
+
if (!this.currentGroup ||
|
|
427
|
+
!execution ||
|
|
428
|
+
!execution.depends_on ||
|
|
429
|
+
!execution.stop_if_dependent_stops)
|
|
430
|
+
continue;
|
|
431
|
+
if (execution.depends_on.includes(opId)) {
|
|
432
|
+
this.stopTaskManagerOperation(this.currentGroup, nextOpId);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
return promise;
|
|
437
|
+
}
|
|
438
|
+
getStatus(reason, type) {
|
|
439
|
+
const map = {
|
|
440
|
+
[StopReasons.COMPLETED]: {
|
|
441
|
+
ops: Statuses.SUCCESS,
|
|
442
|
+
flow: Statuses.SUCCESS,
|
|
443
|
+
},
|
|
444
|
+
[StopReasons.EXPIRED]: { ops: Statuses.SUCCESS, flow: Statuses.SUCCESS },
|
|
445
|
+
[StopReasons.STOPPED]: { ops: Statuses.STOPPED, flow: Statuses.STOPPED },
|
|
446
|
+
[StopReasons.RESTART]: { ops: Statuses.STOPPED, flow: Statuses.STOPPED },
|
|
447
|
+
[StopReasons.QUIT]: { ops: Statuses.FAILED, flow: Statuses.FAILED },
|
|
448
|
+
[StopReasons.UNKNOWN]: { ops: Statuses.FAILED, flow: Statuses.FAILED },
|
|
449
|
+
};
|
|
450
|
+
return map[reason][type];
|
|
451
|
+
}
|
|
452
|
+
getOpStateIndex(opId) {
|
|
453
|
+
const index = this.operations.findIndex((op) => op.id === opId);
|
|
454
|
+
if (index === -1) {
|
|
455
|
+
throw new Error(`Operation not found for ID: ${opId}`);
|
|
456
|
+
}
|
|
457
|
+
return index;
|
|
458
|
+
}
|
|
459
|
+
build() {
|
|
460
|
+
this.opMap = this.createOperationMap();
|
|
461
|
+
this.validateExecutionPlan();
|
|
462
|
+
this.executionPlan = this.createExecutionPlan();
|
|
463
|
+
this.dependecyMap = this.createDependencyMap();
|
|
464
|
+
}
|
|
465
|
+
init() {
|
|
466
|
+
const flow = this.repository.getFlow(this.job);
|
|
467
|
+
if (flow && flow.state.status !== 'waiting-for-job-definition') {
|
|
468
|
+
this.definition = flow.jobDefinition;
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
const now = Date.now();
|
|
472
|
+
const flow = createInitialFlow(this.job, this.project, this.definition, this.operations, this.status, now);
|
|
473
|
+
this.repository.setflow(this.job, flow);
|
|
474
|
+
this.setDefaults(flow.id, this.project, this.definition);
|
|
475
|
+
}
|
|
476
|
+
if (!this.definition) {
|
|
477
|
+
throw new Error('Job Definition Not Specified');
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import TaskManager from './TaskManager.js';
|
|
2
|
+
/**
|
|
3
|
+
* TaskManagerRegistry
|
|
4
|
+
*
|
|
5
|
+
* A singleton registry to track active TaskManager instances, keyed by `jobId`.
|
|
6
|
+
*
|
|
7
|
+
* In a system where jobs are processed via isolated TaskManager instances,
|
|
8
|
+
* this registry provides global visibility and control over running jobs
|
|
9
|
+
* without violating encapsulation or spawning duplicates.
|
|
10
|
+
*
|
|
11
|
+
* ---------------------------------------------------------------------------------------
|
|
12
|
+
* ✅ WHY THIS EXISTS:
|
|
13
|
+
* ---------------------------------------------------------------------------------------
|
|
14
|
+
* - Each `TaskManager` is designed to handle a single job at a time.
|
|
15
|
+
* - The API (or other system components) should not create new instances blindly.
|
|
16
|
+
* - Instead, they can **query the registry** for the job-specific TaskManager.
|
|
17
|
+
* - This avoids duplicate execution and lets the system safely:
|
|
18
|
+
* - Pause/resume/stop jobs
|
|
19
|
+
* - Fetch logs or live state
|
|
20
|
+
* - Broadcast updates via WebSocket
|
|
21
|
+
*
|
|
22
|
+
* ---------------------------------------------------------------------------------------
|
|
23
|
+
* FUTURE USE CASES:
|
|
24
|
+
* ---------------------------------------------------------------------------------------
|
|
25
|
+
* - **Parallel Job Execution:**
|
|
26
|
+
* You’ll eventually support multiple jobs running at the same time (concurrently).
|
|
27
|
+
* This registry is the backbone for that. Each job gets its own `TaskManager`,
|
|
28
|
+
* but the registry keeps them accessible and uniquely identifiable.
|
|
29
|
+
*
|
|
30
|
+
* - **Safe Shutdown / Cleanup:**
|
|
31
|
+
* On server shutdown, loop through all managers via the registry
|
|
32
|
+
* and gracefully shut down active tasks.
|
|
33
|
+
*
|
|
34
|
+
* - Use `.register()` when starting a job
|
|
35
|
+
* - Use `.remove()` once the job finishes (success/fail)
|
|
36
|
+
* - `.get()` to safely access a manager by ID
|
|
37
|
+
* - Singleton ensures the same instance is used everywhere
|
|
38
|
+
*/
|
|
39
|
+
export declare class TaskManagerRegistry {
|
|
40
|
+
private static instance;
|
|
41
|
+
private registry;
|
|
42
|
+
private constructor();
|
|
43
|
+
static getInstance(): TaskManagerRegistry;
|
|
44
|
+
register(jobId: string, manager: TaskManager): void;
|
|
45
|
+
get(jobId: string): TaskManager | undefined;
|
|
46
|
+
remove(jobId: string): void;
|
|
47
|
+
has(jobId: string): boolean;
|
|
48
|
+
stop(): Promise<void>;
|
|
49
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TaskManagerRegistry
|
|
3
|
+
*
|
|
4
|
+
* A singleton registry to track active TaskManager instances, keyed by `jobId`.
|
|
5
|
+
*
|
|
6
|
+
* In a system where jobs are processed via isolated TaskManager instances,
|
|
7
|
+
* this registry provides global visibility and control over running jobs
|
|
8
|
+
* without violating encapsulation or spawning duplicates.
|
|
9
|
+
*
|
|
10
|
+
* ---------------------------------------------------------------------------------------
|
|
11
|
+
* ✅ WHY THIS EXISTS:
|
|
12
|
+
* ---------------------------------------------------------------------------------------
|
|
13
|
+
* - Each `TaskManager` is designed to handle a single job at a time.
|
|
14
|
+
* - The API (or other system components) should not create new instances blindly.
|
|
15
|
+
* - Instead, they can **query the registry** for the job-specific TaskManager.
|
|
16
|
+
* - This avoids duplicate execution and lets the system safely:
|
|
17
|
+
* - Pause/resume/stop jobs
|
|
18
|
+
* - Fetch logs or live state
|
|
19
|
+
* - Broadcast updates via WebSocket
|
|
20
|
+
*
|
|
21
|
+
* ---------------------------------------------------------------------------------------
|
|
22
|
+
* FUTURE USE CASES:
|
|
23
|
+
* ---------------------------------------------------------------------------------------
|
|
24
|
+
* - **Parallel Job Execution:**
|
|
25
|
+
* You’ll eventually support multiple jobs running at the same time (concurrently).
|
|
26
|
+
* This registry is the backbone for that. Each job gets its own `TaskManager`,
|
|
27
|
+
* but the registry keeps them accessible and uniquely identifiable.
|
|
28
|
+
*
|
|
29
|
+
* - **Safe Shutdown / Cleanup:**
|
|
30
|
+
* On server shutdown, loop through all managers via the registry
|
|
31
|
+
* and gracefully shut down active tasks.
|
|
32
|
+
*
|
|
33
|
+
* - Use `.register()` when starting a job
|
|
34
|
+
* - Use `.remove()` once the job finishes (success/fail)
|
|
35
|
+
* - `.get()` to safely access a manager by ID
|
|
36
|
+
* - Singleton ensures the same instance is used everywhere
|
|
37
|
+
*/
|
|
38
|
+
export class TaskManagerRegistry {
|
|
39
|
+
constructor() {
|
|
40
|
+
this.registry = new Map();
|
|
41
|
+
}
|
|
42
|
+
static getInstance() {
|
|
43
|
+
if (!TaskManagerRegistry.instance) {
|
|
44
|
+
TaskManagerRegistry.instance = new TaskManagerRegistry();
|
|
45
|
+
}
|
|
46
|
+
return TaskManagerRegistry.instance;
|
|
47
|
+
}
|
|
48
|
+
register(jobId, manager) {
|
|
49
|
+
this.registry.set(jobId, manager);
|
|
50
|
+
}
|
|
51
|
+
get(jobId) {
|
|
52
|
+
return this.registry.get(jobId);
|
|
53
|
+
}
|
|
54
|
+
remove(jobId) {
|
|
55
|
+
this.registry.delete(jobId);
|
|
56
|
+
}
|
|
57
|
+
has(jobId) {
|
|
58
|
+
return this.registry.has(jobId);
|
|
59
|
+
}
|
|
60
|
+
async stop() {
|
|
61
|
+
const stopPromises = [];
|
|
62
|
+
for (const [jobId, manager] of this.registry.entries()) {
|
|
63
|
+
const p = manager.stop('quit').finally(() => this.registry.delete(jobId));
|
|
64
|
+
stopPromises.push(p);
|
|
65
|
+
}
|
|
66
|
+
await Promise.all(stopPromises);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import TaskManager from '../TaskManager.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a dependency map for all operations.
|
|
4
|
+
*
|
|
5
|
+
* Returns a Map of operation ID -> {
|
|
6
|
+
* dependencies: operation IDs this op waits for
|
|
7
|
+
* dependents: operation IDs that wait for this op
|
|
8
|
+
* }
|
|
9
|
+
*
|
|
10
|
+
* This allows the task manager to:
|
|
11
|
+
* - Dynamically trigger downstream ops when upstream completes
|
|
12
|
+
* - Track dependencies and dependents efficiently during execution
|
|
13
|
+
* - Use alongside the execution plan to resolve execution flow
|
|
14
|
+
*/
|
|
15
|
+
export declare function createDependencyMap(this: TaskManager): Map<string, {
|
|
16
|
+
dependencies: string[];
|
|
17
|
+
dependents: string[];
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a dependency map for all operations.
|
|
3
|
+
*
|
|
4
|
+
* Returns a Map of operation ID -> {
|
|
5
|
+
* dependencies: operation IDs this op waits for
|
|
6
|
+
* dependents: operation IDs that wait for this op
|
|
7
|
+
* }
|
|
8
|
+
*
|
|
9
|
+
* This allows the task manager to:
|
|
10
|
+
* - Dynamically trigger downstream ops when upstream completes
|
|
11
|
+
* - Track dependencies and dependents efficiently during execution
|
|
12
|
+
* - Use alongside the execution plan to resolve execution flow
|
|
13
|
+
*/
|
|
14
|
+
export function createDependencyMap() {
|
|
15
|
+
const map = new Map();
|
|
16
|
+
// Initialize map with declared dependencies
|
|
17
|
+
for (const op of this.operations) {
|
|
18
|
+
map.set(op.id, {
|
|
19
|
+
dependencies: op.execution?.depends_on ?? [],
|
|
20
|
+
dependents: [],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
// Populate dependents for each dependency
|
|
24
|
+
for (const [id, { dependencies }] of map.entries()) {
|
|
25
|
+
for (const depId of dependencies) {
|
|
26
|
+
if (!map.has(depId))
|
|
27
|
+
continue;
|
|
28
|
+
map.get(depId).dependents.push(id);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return map;
|
|
32
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import TaskManager from '../TaskManager.js';
|
|
2
|
+
import { ExecutionContext } from '../TaskManager.js';
|
|
3
|
+
/**
|
|
4
|
+
* Converts the list of operations into a structured execution plan.
|
|
5
|
+
*
|
|
6
|
+
* This function focuses only on grouping operations by execution group.
|
|
7
|
+
* Dependency resolution (dependencies + dependents) is now handled separately
|
|
8
|
+
* in `createDependencyMap()`.
|
|
9
|
+
*
|
|
10
|
+
* Each `ExecutionContext` includes:
|
|
11
|
+
* - `group`: The logical group name
|
|
12
|
+
* - `ops`: Array of operations with their `id` only
|
|
13
|
+
*/
|
|
14
|
+
export declare function createExecutionPlan(this: TaskManager): ExecutionContext[];
|