[英]How to properly delay the loading of a Node/Express API using tasks.json in VS Code
我有一个微服务项目,我在单个 VS Code 实例中进行调试。 我在 launch.json 中使用 Compounds 来启动/调试。
有一个所有其他服务都依赖的“元数据”服务,因此它需要在任何其他服务启动之前运行。
我已经解决了这个问题,在过去的 10 个月里它对我来说一直很顺利,但最近它自发地崩溃了。
这就是我所拥有的。
启动.json:
化合物:
{
"name": "API-only",
"stopAll": true,
"configurations": [
"Metadata API",
"Auth API"
]
}
...以及化合物中的个人 API 配置:
{
"type": "node",
"request": "launch",
"name": "Metadata API",
"program": "${workspaceFolder}/metadata-api/bin/www",
"envFile": "${workspaceFolder}/metadata-api/.env",
"skipFiles": [
"<node_internals>/**/*.js",
"${workspaceRoot}/node_modules/**/*.js"
],
"presentation": {
"hidden": false,
"group": "apis",
"order": 1
}
},
{
"type": "node",
"request": "launch",
"name": "Auth API",
"program": "${workspaceFolder}/auth-api/bin/www",
"envFile": "${workspaceFolder}/auth-api/.env",
"skipFiles": [
"<node_internals>/**/*.js",
"${workspaceRoot}/node_modules/**/*.js"
],
"preLaunchTask": "Preload Delay",
"presentation": {
"hidden": true,
"group": "",
"order": 1
}
}
您可以看到“preLaunchTask”是在 Auth API 中设置的,但不是元数据 API 中设置的。这是:
任务.json :
{
"version": "2.0.0",
"tasks": [
{
"label": "Preload Delay",
"type": "shell",
"command": "sleep 3",
"windows": {
"command": "ping 127.0.0.1 -n 3 > nul"
},
"group": "none",
"presentation": {
"reveal": "silent",
"panel": "shared",
"revealProblems": "onProblem"
}
}
]
}
我以前可以先在 VSC 调用堆栈面板中查看元数据加载,然后在 3 秒后查看身份验证。 现在,它们都立即出现并且经常出现,Auth 失败,因为它不再尊重等待元数据首先加载的延迟,因此它可以调用它并自行加载。
果然,如果我先手动启动Metadata,或者手动暂停Auth等待Metadata加载,每次都有效。
这些配置在 10 多个月内都没有改变,所以我怀疑最近的 VSC 更新必须打破这个? 还有别的办法吗? 我没有找到太多关于 go 的信息。
我浏览了 VS Code 文档,发现您的任务有两个问题。json。
1-您需要为上述场景分别创建两个不同的任务,例如
{ "version": "2.0.0", "tasks": [{ "label": "Client Build", "command": "gulp", "args": ["build"], "options": { "cwd": "${workspaceFolder}/client" } }, { "label": "Server Build", "command": "gulp", "args": ["build"], "options": { "cwd": "${workspaceFolder}/server" } }, { "label": "Build", "dependsOn": ["Client Build", "Server Build"] } ] }
2-您需要设置“dependsOrder”:“sequence”并配置依赖项,例如
{ "label": "One", "type": "shell", "command": "echo Hello ", "dependsOrder": "sequence", "dependsOn": ["Two", "Three"] }
了解有关复合任务的更多信息? 祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.