将任务添加到Google Cloud Tasks时为DEADLINE_EXCEEDED [英] DEADLINE_EXCEEDED while adding tasks to Google Cloud Tasks

查看:218
本文介绍了将任务添加到Google Cloud Tasks时为DEADLINE_EXCEEDED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Node.js客户端向Google Cloud Tasks添加任务时,偶尔会遇到名为DEADLINE_EXCEEDED的错误.我仅尝试在for循环中添加17个任务.不知道为什么偶尔会发生这种情况,有时效果很好!

I'm occasionally getting an error called DEADLINE_EXCEEDED while adding tasks to Google Cloud Tasks from Node.js client. It's only 17 tasks that I tried to add in a for-loop. Not sure why this is happening occasionally and sometimes works perfectly fine!

这是详细的错误日志:

Error: 4 DEADLINE_EXCEEDED: Deadline exceeded
    at Object.callErrorFromStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
    at Object.onReceiveStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
    at Object.onReceiveStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)
    at Object.onReceiveStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
    at Http2CallStream.outputStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/call-stream.js:115:74)
    at Http2CallStream.maybeOutputStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/call-stream.js:154:22)
    at Http2CallStream.endCall (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/call-stream.js:140:18)
    at Http2CallStream.cancelWithStatus (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/call-stream.js:443:14)
    at Timeout.<anonymous> (/Users/gijo/Desktop/workspace/flying-press-server/node_modules/@grpc/grpc-js/build/src/deadline-filter.js:59:28)
    at listOnTimeout (internal/timers.js:549:17) {
  code: 4,
  details: 'Deadline exceeded',
  metadata: Metadata { internalRepr: Map {}, options: {} }
}

我以为我达到了一些配额.但是经过检查,它们都没有超出.

I thought I hit some quotas. But on checking, none of them has exceeded.

这是我创建队列的方法(upsert):

Here is how I've created the queue (upsert):

const client = require('./client');

module.exports = async (queue_name, concurrent) => {
  return client.updateQueue({
    queue: {
      name: client.queuePath(
        process.env.GCP_PROJECT,
        process.env.GCP_QUEUE_LOCATION,
        queue_name,
      ),
      rateLimits: {
        maxConcurrentDispatches: concurrent,
        maxDispatchesPerSecond: concurrent,
        maxBurstSize: 100,
      },
      retryConfig: {
        maxAttempts: 3,
        unlimitedAttempts: false,
        maxRetryDuration: {
          seconds: 3600,
        },
        minBackoff: {
          seconds: 60,
        },
        maxBackoff: {
          seconds: 300,
        },
        maxDoublings: 3,
      },
    },
  });
};

这是我添加任务的方式:

and here is how I'm adding tasks:

const client = require('./client');

module.exports = async (queue_name, url, config) => {
  return client.createTask({
    parent: client.queuePath(
      process.env.GCP_PROJECT,
      process.env.GCP_QUEUE_LOCATION,
      queue_name,
    ),
    task: {
      httpRequest: {
        httpMethod: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        url: `${process.env.OPTIMIZER_URL}/optimize-page`,
        body: Buffer.from(JSON.stringify({ url, config })).toString(
          'base64',
        ),
      },
    },
  });
};

推荐答案

创建任务时,我之前在Cloud Functions和App Engine中遇到了这个确切的问题.发生这种情况是因为我没有正确地创建任务Promise.这会导致请求挂起并最终超时,但这只是偶尔发生.基本上,请求会在异步调用完成之前结束,这会导致无服务器"运行时出现问题,例如App Engine,Cloud Functions,Cloud Run等.

I've hit this exact issue before in Cloud Functions and App Engine when creating tasks. It happened because I wasn't properly awaiting on the create task promise. This causes the request to hang open and eventually hit a timeout, but it only happens sporadically. Basically, the request ends before the async call is completed, which causes issues in "serverless" runtimes like App Engine, Cloud Functions, Cloud Run, etc.

要解决此问题,请确保在从请求返回之前,在对createTask的调用中执行await,否则对所有任务promise执行await.与Promise.all().

To fix this, ensure you are doing an await on the call to createTask or otherwise await on all of the task promises before returning from the request, e.g. with Promise.all().

这篇关于将任务添加到Google Cloud Tasks时为DEADLINE_EXCEEDED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆