簡體   English   中英

在nodejs中處理來自excel文件的數據時請求超時

[英]request timeout while processing data from excel file in nodejs

我有一張帶有數據的 excel 表,我在讀取數據后正在處理它。 問題是,即使處理沒有完成,請求也會在 postman 中超時。

 xlsxj({
          input: filepath,//path of the file
          output: null, // I am not taking any output of the file
          sheet: "Party Master"
        }, async function (err, result) {
          if (err) {
            res.send(err);
          } else {
            try {
                for(let row of result) { // more than 1000 iterations
                await fun1(row);
                await fun2(row);
                await fun3(row);
                }
                return res.send('all done');
             }
              catch(err){
                   console.log(err);
                  }

         }
    })

我哪里錯了?

您是 API 超時,因為文件處理需要時間。 如果您使用的是express框架,默認的 API 超時為2 分鍾,您可以增加 API 的超時。

如果您使用的是快遞,那么您可以簡單地做

 req.setTimeout(500000); // time in ms

I have found a solution. Return the response in finally block.

xlsxj({
          input: filepath,//path of the file
          output: null, // I am not taking any output of the file
          sheet: "Party Master"
        }, async function (err, result) {
          if (err) {
            res.send(err);
          } else {
            try {
                for(let row of result) { // more than 1000 iterations
                await fun1(row);
                await fun2(row);
                await fun3(row);
                }
                return res.send('all done');
             }
              catch(err){
                   console.log(err);
                  }
finally{
return res.send('all done')
}

         }
    })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM