2

I got this error when task is trying processing. This is my nodejs code

async function quickstart(message : any) {
  // TODO(developer): Uncomment these lines and replace with your values.
  const project = "";//projectid
  const queue = "";//queuename
  const location = "";//region
  const payload = JSON.stringify({
    id: message.id,
    data: message.data,
    attributes: message.attributes,
  });
  const inSeconds = 180;

  // Construct the fully qualified queue name.
  const parent = client.queuePath(project, location, queue);

  const task = {
    appEngineHttpRequest: {
      headers: {"Content-type": "application/json"},
      httpMethod: protos.google.cloud.tasks.v2.HttpMethod.POST,
      relativeUri: "/api/download",
      body: "",
    },
    scheduleTime: {},
  };

  if (payload) {
    task.appEngineHttpRequest.body = Buffer.from(payload).toString("base64");
  }

  if (inSeconds) {
    task.scheduleTime = {
      seconds: inSeconds + Date.now() / 1000,
    };
  }

  const request = {
    parent: parent,
    task: task,
  };

  console.log("Sending task:");
  console.log(task);
  // Send create task request.
  const [response] = await client.createTask(request);
  console.log(`Created task ${response.name}`);
  console.log("Created task");
  return true;
}

The task is created without issue. However, it didnt trigger my cloud function and I got 404 or unhandled exception in my cloud logs. I have no idea whats going wrong.

enter image description here

I also did test with gcloud cli without the issue. Gcloud cli able to trigger my cloud function based on provided url.

scarlet pro
  • 181
  • 12
  • Is the app engine app in the same project as the queue definition? Is the app engine app addressable at path `/api/download`? I'd also look in the GCP Cloud Logging to see if there are additional diagnostics available there. – Kolban May 20 '22 at 19:32
  • Can you please update your post with the logs? Have you tried [this example](https://cloud.google.com/tasks/docs/tutorial-gcf) about Trigger Cloud Functions using Cloud Tasks? – Osvaldo May 23 '22 at 21:55

0 Answers0