简体   繁体   English

安排 API 调用以将结果保存到数据库

[英]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 中。

How to schedule Cloudwatch Event 如何安排 Cloudwatch 活动

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.

相关问题 为什么我不能将节点api调用的结果保存为变量并通过Express发送? - Why can't I save the results of my node api call to variable and send it with Express? 使用API​​调用创建新数据库 - Create new database with API call 猫鼬在一个数据库调用中保存条件? - Mongoose save with condition in one database call? 使用外部API调用和findOneAndUpdate循环结果 - Looping Results with an External API Call and findOneAndUpdate 使用 mongoose 在 mongodb 中保存 API 调用请求 - Save API Call with request in mongodb with mongoose 如何从 REST API 调用中保存 PDF - How to save a PDF from an REST API call 通过Node.js中的函数将数据库结果保存到Dictionary中 - Save database results in Dictionary from a function in Node.js 每当存在数据库调用时,AWS Lambda函数都会导致超时 - AWS Lambda function results in timeout whenever database call is present 在 ndoejs 和 mongoose 中保存到数据库后返回数据时调用套接字 - call socket when return data after save in database in ndoejs and mongoose 将数组提供给 bluebird,调用 API,然后将结果集成到单个 JSON 输出中 - Give an array to bluebird, call an API, then integrating the results into a single JSON output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM