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

推荐订阅源

N
Netflix TechBlog - Medium
罗磊的独立博客
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
T
The Blog of Author Tim Ferriss
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
博客园 - Franky
F
Fortinet All Blogs
D
Docker
博客园 - 司徒正美
腾讯CDC
Recent Announcements
Recent Announcements
The Cloudflare Blog
B
Blog RSS Feed
GbyAI
GbyAI
T
Tailwind CSS Blog
雷峰网
雷峰网
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志

博客园 - 阿牛

在家无缝访问公司内网:我的低成本、高安全远程办公方案 好学生 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);
}