【发布时间】:2022-06-13 02:04:36
【问题描述】:
我说的是这个:https://firebase.google.com/docs/functions/task-functions
我想使用scheduleTime 参数将任务排入队列以在将来运行,但我必须能够取消这些任务。
我希望有可能做这样的伪代码:
const task = await queue.enqueue({ foo: true })
// Then...
await queue.cancel(task.id)
我正在使用 Node.js。如果无法使用firebase-admin 取消计划任务,我可以直接使用@google-cloud/tasks 以某种方式解决它吗?
PS:我还创建了一个功能请求:https://github.com/firebase/firebase-admin-node/issues/1753
【问题讨论】:
-
可以使用
@google-cloud/tasksSDK 删除任务,但您需要任务名称/ID。enqueue()似乎返回void而不是 ID。在Github 上找到了相关代码,其中函数什么都不返回。 -
@Dharmaraj 这似乎是 OP 的答案。您能否将您的评论转换为答案?
-
如果评论提供了一种解决方法来以某种方式获取任务 ID 并取消任务,它将成为一个非常有用的答案。
-
您能否为解决方法添加更多用例详细信息?哪些任务是您要删除的任务,您希望如何删除它们? Node.js Cloud Tasks 库也可以list the tasks,这在此处可能很有用,具体取决于您希望如何实现它。就使用您的确切代码而言,就像 Dharmaraj 解释的那样。
标签: firebase google-cloud-functions firebase-admin google-cloud-tasks