我有一个API调用需要大约5-10分钟来处理.我在它周围设置了一个超时方法,以便我得到一个状态为排队的即时API响应.
简单的视觉如下
doWork(object) => { /*... Takes 5 minutes */ }
app.post('/longProcess',(req,res)=> {
setTimeout(this.doWork(req.body), 1000);
res.send({ status: 'queued' });
})
Run Code Online (Sandbox Code Playgroud)
这适用于第一个立即响应的请求.但第二个请求被锁定等待doWork完成.
而不是使用SetTimeout,我真正想要做的是将longProcess发送到一个单独的单线程,逐个队列和处理这些.
有什么建议?
我有一个使用express,mongodb的api,并且使用AJV验证来验证传入的请求。
//JSONSchema
var recordJsonSchema = {
type: "object",
properties: {
name: { type: "string" },
idNumber: { type: "number" },
content: { type: "string" }
},
required: ['name','idNumber']
}
Run Code Online (Sandbox Code Playgroud)
我将使用这种JSON模式来验证传入的请求。
app.post('/record', (req,res) => {
let errors = ajv.inspect(req.body, recordJsonSchema)
return errors ? res.send(errors) : res.send(this.handler(req));
})
Run Code Online (Sandbox Code Playgroud)
这工作正常并且非常快。我也喜欢JsonSchema,因为它遵循OpenAPI标准。
不幸的是,为了通过mongoose读/写mongo,我还需要创建一个MongoSchema for Record。它们非常相似,但在处理必填字段等方面却有些不同。
var recordSchema = new Schema({
name: { type: "string", required: true },
idNumber: { type: "number", required: true },
content: { type: "string" }
})
Run Code Online (Sandbox Code Playgroud)
因此,对于我的记录模型,我现在有两个模式。一种用于JSONschema,另一种用于处理Mongo读/写。
我正在寻找一种削减MongoSchema的方法,有什么建议吗?
我有这个应用程序,它使用 Webbrowser 控件进行自动浏览。我需要想出一种方法来自动关闭浏览器(处置),然后创建另一个实际工作的实例。
这是我迄今为止拥有的一些代码。
this.webBrowser2 = new System.Windows.Forms.WebBrowser();
this.webBrowser2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.webBrowser2.Location = new System.Drawing.Point(0, 34);
this.webBrowser2.MinimumSize = new System.Drawing.Size(20, 20);
this.webBrowser2.Name = "webBrowser2";
this.webBrowser2.ScriptErrorsSuppressed = true;
this.webBrowser2.Size = new System.Drawing.Size(616, 447);
this.webBrowser2.TabIndex = 1;
Run Code Online (Sandbox Code Playgroud)
所以我在想是否要处理掉 webbrower 实例。
webBrowser2.dispose();
Run Code Online (Sandbox Code Playgroud)
然后创建 webbrowser 对象的新实例。
WebBrowser w = new WebBroswer();
w.Navigate(url);
Run Code Online (Sandbox Code Playgroud)
不幸的是这不起作用。浏览器的新实例不会显示,并且已处理的浏览器对象只是在窗口窗体中保持冻结状态。
我做错了什么吗?
谢谢
class A
{
public List<string> list;
}
class B
{
public string[] array;
}
Run Code Online (Sandbox Code Playgroud)
你会如何映射这个?
我试过了
CreateMap<A,B>();
Run Code Online (Sandbox Code Playgroud)
那不行
我有一个Git仓库,在不同分支上有多个项目
我想将它们分解为不同的独立存储库。我已经为每个仓库创建了新的仓库。我希望每个分支及其所有提交历史记录都移到新的单独存储库中。
c# ×2
express ×2
node.js ×2
arrays ×1
automapper ×1
collections ×1
dispose ×1
git ×1
git-merge ×1
git-rebase ×1
git-remote ×1
jsonschema ×1
mongodb ×1
queue ×1
validation ×1
winforms ×1