Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Explicitly provide task name when enqueuing new Cloud Task #2039

Closed
wnielson opened this issue Jan 10, 2023 · 2 comments
Closed

[FR] Explicitly provide task name when enqueuing new Cloud Task #2039

wnielson opened this issue Jan 10, 2023 · 2 comments

Comments

@wnielson
Copy link

wnielson commented Jan 10, 2023

Is your feature request related to a problem? Please describe.
No.

Describe the solution you'd like
The Cloud Tasks API allows you to specify a task's name explicitly but the SDK does not currently expose this. This is useful for task de-duplication, for example. It would be great to expose this via TaskOptions through a name property like so:

const queue = getFunctions().taskQueue("taskFunction");
queue.enqueue(
  { ... },
  { name: "task-name" }
);

Describe alternatives you've considered
The workaround is to use the @google-cloud/tasks SDK directly like so:

import { CloudTasksClient } from "@google-cloud/tasks";

const client = new CloudTasksClient();

const name = "task-name";
const projectId = "project-name";
const location = "us-central1";
const functionName = "taskFunction";
const serviceAccountEmail = `${projectId}@appspot.gserviceaccount.com`;

const parent = client.queuePath(
  projectId,
  location,
  functionName
);

const url = `https://${location}-${projectId}.cloudfunctions.net/${functionName}`;

client
  .createTask({
    parent: parent,
    task: {
      name: `${parent}/tasks/${name}`,
      httpRequest: {
        headers: {
          "Content-Type": "application/json",
        },
        body: Buffer.from(
          JSON.stringify({ data: {} })
        ).toString("base64"),
        httpMethod: "POST",
        url: url,
        oidcToken: { serviceAccountEmail },
      },
    },
  });

Additional context
While the solution above works, it is clearly far more verbose and cumbersome than if the firebase admin were to expose this functionality directly.

@google-oss-bot
Copy link

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@wnielson
Copy link
Author

I think this has been implemented in #2216?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants