如何解决NodeJS-等待直到上一个请求的派生过程完成后,再使用队列方案服务下一个请求
我有一个带有POST请求的http服务器来运行程序(使用nodejs生成)。这里的目标是即使有多个用户可以请求运行该程序,该程序一次只能运行一个用户。
我有基本代码:
C:\Users\USER\Desktop\extension>tfx extension create --trace-level debug
(node:19816) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
TFS Cross Platform Command Line Interface v0.8.3
Copyright Microsoft Corporation
2020-10-29T15:52:51.089Z : cache.getItem
2020-10-29T15:52:51.098Z : merger.merge
2020-10-29T15:52:51.099Z : merger.gatherManifests
2020-10-29T15:52:51.106Z : Merging 1 manifest from the following paths:
2020-10-29T15:52:51.107Z : vss-extension.json
2020-10-29T15:52:51.112Z : Path 'C:\Users\USER\Desktop\extension\node_modules\vss-web-extension-sdk\lib` is a directory. Adding all contained files (recursive).
2020-10-29T15:52:51.115Z : -- VSS.SDK.js
2020-10-29T15:52:51.117Z : -- VSS.SDK.min.js
2020-10-29T15:52:51.120Z : Path 'C:\Users\USER\Desktop\extension\BuildTaskFolder` is a directory. Adding all contained files (recursive).
2020-10-29T15:52:51.121Z : -- task.json
2020-10-29T15:52:51.130Z : Generating [Content_Types].xml
2020-10-29T15:52:51.137Z : Error: There were errors with your extension. Address the following and re-run the tool.
2020-10-29T15:52:51.137Z : One or more 'categories' must be provided.
2020-10-29T15:52:51.137Z : at C:\Users\USER\AppData\Roaming\npm\node_modules\tfx-cli\_build\exec\extension\_lib\merger.js:212:39
error: Error: There were errors with your extension. Address the following and re-run the tool.
error: One or more 'categories' must be provided.
我想在上面添加一个队列,但不确定如何
给出如下队列:
app.post('/run',(req,res) => {
const p = new Promise((resolve) => {
const spawn = require("child_process").spawn;
const simulatorProcess = spawn('python',"path/to/script.py");
simulatorProcess.stdout.on('data',(data) => {
if (data == "done") {
resolve("program is complete")
}
});
});
p.then(response => {
if (response == "program is complete") {
res.send('Done')
}
})
})
我如何修改基本代码以等待派生程序执行完毕并为队列中的下一个用户提供服务?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。