matth
matth

Reputation: 573

Google Cloud Tasks ignoring `dispatchDeadline`, invoked from node.js

I have a long-running task in a Cloud Run container (typically ~12 minutes) that I want to trigger via Google Tasks. Everything seems to be working except that no matter what I set dispatchDeadline to, the task times-out in Cloud Tasks after 600s and is retried. The original process in Cloud Run keeps running for some time and completes, but the response to the http request that triggered it is ignored after it times out in Cloud Tasks.

The task is created in node like this

  const { CloudTasksClient } = require('@google-cloud/tasks');
  const client = new CloudTasksClient();

  ...

  const parent = client.queuePath(projectm region, queue);
  const task = {
    httpRequest: {
      httpMethod: 'POST',
      url: cloudRunUrl
      oidcToken: {
        serviceAccountEmail
      },
      dispatchDeadline: '1500s'
      headers: { 'Content-Type': 'application/json' },
      body: dataBuffer.toString('base64')
    }
  };

  const [response] = await client.createTask({ parent, task });

After 10 minutes I see the that the task is being retried in the Cloud Tasks console, and the Cloud Run instance gets another invocation:

View of the task in Google Cloud Console - note retrying after 600s with no response

The dispatchDeadline property is documented in the REST API docs and in the node.js API docs. I've tried is as above, and also as in the node docs like:

const dms = require('@google-cloud/dms');

...

task = {
  httpRequest: {
    ...
    dispatchDeadline: dms.protos.google.protobuf.Duration.create({ seconds: 1500, nanos: 0 }),
  }
}

How can I change the default timeout when creating a task from node?

Upvotes: 1

Views: 1211

Answers (2)

kym
kym

Reputation: 1193

As of V3.0.2 of the client library, this works:

const { CloudTasksClient } = require('@google-cloud/tasks');
const client = new CloudTasksClient();
client.createTask({
  dispatchDeadline: { seconds: 1500 },
  httpRequest: { ... }
}).then(([task]) => {
  console.log('created task with dispatchDeadline', task.dispatchDeadline);
});

Upvotes: 2

matth
matth

Reputation: 573

Turns out I put the dispatchDeadline at the wrong level of the task object. The task object should look like this, and should indeed use an IDeadline object for the dispatchDeadline property:

const task = {
  httpRequest: {
    httpMethod: 'POST',
    url: cloudRunUrl
    oidcToken: {
      serviceAccountEmail
    },
    headers: { 'Content-Type': 'application/json' },
    body: dataBuffer.toString('base64')
  },
  dispatchDeadline: dms.protos.google.protobuf.Duration.create({ seconds: 1500, nanos: 0 }),
};

Upvotes: 0

Related Questions