每天在特定时间运行查询

时间:2020-09-17 12:20:57

标签: node.js postgresql real-time feathersjs

我正在研究汽车租赁应用程序,我的问题很简单。但我无法表达 现在,无论何时插入订单,我都需要一个在所有订单上都保持运行的任务运行程序。并继续将每日费率添加到应付款总额字段中

例如,如果今天是17/9

OrderStartDate   RentalAmount     TotalDue
17/9/2020 17:00        100              0
17/9/2020 16:00        100              0

18/9 16:00字段会像

OrderStartDate   RentalAmount     TotalDue
17/9/2020 17:00       100              0
17/9/2020 16:00        100             100

18/9 17:00字段会像

OrderStartDate   RentalAmount     TotalDue
17/9/2020 17:00        100             100
17/9/2020 16:00        100             100

我的应用是一个React + Node.js(gql,prisma,nexus) 我对使用Web sockets,feathers-js的实时应用程序进行了研究,但没有找到我真正需要的

2 个答案:

答案 0 :(得分:0)

您可以使用MySql EVENT或TRIGGER来执行此操作。

但是,有更好的方法。当其他行或列被插入或更新时,不必更改某些行和列的位置,而是在需要时使用查询生成总和。例如,

static string url = "https://einvoicing.internal.cleartax.co/v2/eInvoice/download?irns=11eaf48a909dda520db27ff35804d4b42df2c3b6285afee8df586cc4dbd10541";

static HttpClient client = new HttpClient(); // Use same instance over app lifetime!

static async Task DownloadCurrentAsync()
{
     // config headers here or during instance creation
     HttpResponseMessage response = await client.GetAsync(url);
     response.EnsureSuccessStatusCode(); // <= Will throw if unsuccessful
     using (FileStream fileStream = new FileStream("[file name to write]", FileMode.Create, FileAccess.Write, FileShare.None))
     {
         //copy the content from response to filestream
         await response.Content.CopyToAsync(fileStream);
     }
}

另一种方法是使用运行总数查询。您应该阅读有关此内容。

答案 1 :(得分:0)

您需要安排一项每天(或每分钟,每小时任何时间)运行的作业,这意味着始终以给定的时间间隔运行。

这些被称为cron作业,

有类似https://www.npmjs.com/package/node-cron的库,详细示例https://www.thirdrocktechkno.com/blog/how-to-set-up-a-cron-job-in-nodejs/

或者您也可以在服务器调度程序上调度作业(更好的方法)

相关问题