[英]Scheduling an API call to save results to a database
I currently have a MERN stack web application hosted on Zeit, which is a simple stock simulator.我目前在 Zeit 上托管了一个 MERN 堆栈 Web 应用程序,这是一个简单的股票模拟器。 I would like to schedule an API call to an endpoint every weekday at 4:00pm to pull some market data for the day, and save it to a MongoDB database.我想在每个工作日的下午 4:00 安排对端点的 API 调用,以提取当天的一些市场数据,并将其保存到 MongoDB 数据库中。 What is the best way to do this?做这个的最好方式是什么? For reference I am familiar with Microsoft Azure, and AWS.作为参考,我熟悉 Microsoft Azure 和 AWS。 Thanks谢谢
In AWS, you can use a CloudWatch events rule that triggers a lambda function every weekday at 4:00pm.在 AWS 中,您可以使用 CloudWatch 事件规则,该规则在每个工作日的下午 4:00 触发 lambda 函数。 Lambda function should have code to read the data and save data in MongoDB. Lambda 函数应该有代码来读取数据并将数据保存在 MongoDB 中。
You can use Azure Functions with time trigger for it:您可以将 Azure Functions 与时间触发器一起使用:
function.json函数.json
{
"schedule": "0 0 4 * * *",
"name": "myTimer",
"type": "timerTrigger",
"direction": "in"
}
JavaScript code: JavaScript 代码:
module.exports = function (context, myTimer) {
var timeStamp = new Date().toISOString();
if (myTimer.IsPastDue)
{
context.log('Node is running late!');
}
context.log('Node timer trigger function ran!', timeStamp);
//LOGIC TO PERFORM REQUEST / INSERT on Mongo
context.done();
};
more info: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=javascript更多信息: https : //docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=javascript
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.