惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The GitHub Blog
The GitHub Blog
J
Java Code Geeks
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Vercel News
Vercel News
腾讯CDC
博客园 - 聂微东
The Cloudflare Blog
F
Fortinet All Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
Last Week in AI
Last Week in AI
B
Blog

博客园 - 阿牛

在家无缝访问公司内网:我的低成本、高安全远程办公方案 好学生 Deepseek 的学习过程 DeepSeek R1 的推理过程与人类团队处理任务的类比 ColorOS14升级15保持ROOT windows11获取不到IPv6的解决方法 wps插件工具 当github双因子认证遇到鸿蒙手机 从Console中获取VUE的Route参数 雨霖工具 使用Powershell脚本实现微信多开 调试远程GithubAction 备份51CTO买到的视频课程 白嫖Gitee收费服务, 实现瞬时Pages更新 PC微信小程序解密和反编译资源 批量删除gitlab仓库 批量删除github仓库 批量删除gitee的代码库 树莓派系统充分利用SD卡空间 Thinkpad T470p Clover and opencore 吃黑苹果 Catalina 10.15.5
突破Vecel网站最大运行10秒的限制
阿牛 · 2021-11-27 · via 博客园 - 阿牛

设置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);
}