zoukankan      html  css  js  c++  java
  • 突破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 转载请注明出处。
  • 相关阅读:
    Qt中QString,int,char,QByteArray之间相互转换
    Qt中的多线程编程
    在Qt中使用sleep(包含为win and *nix下sleep函数的实现及用法)
    Qt Creator 快捷键
    基于FFmpeg和Qt的播放器 QtAV库
    Ubuntu下APACHE HTTPS安装和配置
    很受欢迎的Linux笔记(短小精悍)
    QT基本使用
    FLV封装格式及分析器工具
    AVPicture、AVFrame和AVPacket
  • 原文地址:https://www.cnblogs.com/evlon/p/15613002.html
Copyright © 2011-2022 走看看