如何增加 cronjobs 的运行时间?

问题描述 投票:0回答:1

总结

在我的

src/pages/api/crons/analytics/test.ts
我有这个

import { prisma } from '../../../../server/db'
import { NextApiRequest, NextApiResponse } from 'next'

// https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration
export const config = {
  maxDuration: 300
}



export default async function handler(request: NextApiRequest, response: NextApiResponse) {
  console.log('now: ', new Date())
  console.log('waiting 30 seconds...')
  await new Promise((resolve) => setTimeout(resolve, 30000))

  console.log('waiting ANOTHER I 30 seconds...')
  await new Promise((resolve) => setTimeout(resolve, 30000))

  console.log('waiting ANOTHER II 30 seconds...')
  await new Promise((resolve) => setTimeout(resolve, 30000))

  console.log('waiting THE LAST 30 seconds...')
  await new Promise((resolve) => setTimeout(resolve, 30000))

  console.log('runtime final: ', new Date())
  response.status(200).json({
    success: true
  })
}

这是我的

vercel.json

{
  "crons": [
    {
      "path": "/api/crons/analytics/test",
      "schedule": "0 15 * * *"
    }
  ]
}

但是,15秒后超时。 我的组织位于

Pro
层。

我正在关注文档的这一部分:https://vercel.com/docs/functions/serverless-functions/runtimes#maxduration

我添加了

config.maxDuration
,但它仍然显示 15 秒。

cron vercel trpc
1个回答
0
投票

很好奇您是否找到了这个问题的解决方案。我也遇到同样的问题。

© www.soinside.com 2019 - 2024. All rights reserved.