• 突破Vecel网站最大运行10秒的限制


    设置Gitee的Webhooks 到Vercel.com 网站后,因为API只能运行10秒,许多任务没有办法正常完成。为了突破限制,可以采用多次请求来完成任务,8+8+8等, 达到24秒以上。

    一、先看一下效果:

     二、实现代码如下:

    import buildPage from 'gitee-pages-build';
    import fetch from 'node-fetch'
    import sleep from 'sleep-anywhere'
    import  URLSearchParams  from 'url-search-params'
    
    export default async function handler(req, res) {
    
      console.log(req.url);
      let currentStep = parseInt(req.query.step || '1');
      let state = req.query.state;
      
    
     
      await doAction(req); 
      res.status(200).json({step: currentStep, code:0, msg:"ok"}) 
    }
    
    async function doAction(req){
      //add your code here...
      console.log('your code here...',new Date())
      await sleep(5000);
    
      console.log('end code here...',new Date())
      // do next step action to get more cpu time
    
      let currentStep = parseInt(req.query.step || '1');
      if(currentStep < 3){
        let state = {currentStep:currentStep}
        // start next time ,to get more time
        await doNext(currentStep + 1,  state);
      }
      else{
        console.log('finished...')
      }
      
    }
    
    async function doNext(step,state){
      
      let url = process.env.API_PAGE_BUILD_SELF_URI || 'http://localhost:3000/api/pagebuild';
      let query = new URLSearchParams({ step:step , state: JSON.stringify(state)}).toString();
      let queryUri = url + '?' + query;
      console.log('doNext ', queryUri, step, state);
      fetch(queryUri)
      await sleep(1000);
    }
    

      

    QQ:273352165 evlon#126.com 转载请注明出处。
  • 相关阅读:
    声明对象指针,调用构造、析构函数的多种情况
    [C++ STL] 常用算法总结
    [C++ STL] map使用详解
    [C++ STL] set使用详解
    [C++ STL] list使用详解
    [C++ STL] deque使用详解
    Servlet课程0424(一) 通过实现Servlet接口来开发Servlet
    CSS盒子模型
    Spring学习之第一个hello world程序
    Java基础面试题
  • 原文地址:https://www.cnblogs.com/evlon/p/15613002.html
Copyright © 2020-2023  润新知