【问题标题】:How to run Pub-Sub functions in Firebase Functions shell如何在 Firebase Functions shell 中运行 Pub-Sub 函数
【发布时间】:2023-04-03 07:01:01
【问题描述】:

我无法在本地 Cloud Functions Shell 中运行我的 pub-sub 触发器。我通过以下方式创建了 Cloud Functions:

export const sendNotifications = functions.pubsub.schedule('0 10 * * *').timeZone('Asia/Kolkata').onRun(async (context) => {
    console.log('running sendNotificationForActivities');
    await sendMessages();
    return 0;
}

正如提到的here,我尝试从我的系统运行firebase functions:shell,然后:

> sendNotifications({data: new Buffer('{"hello":"world"}'), attributes: {foo: 'bar'}})

> sendNotifications({})

和其他变体。以下是我收到的错误堆栈跟踪:

firebase > sendNotificationForActivities({})
'Successfully invoked function.'
firebase > ⚠  TypeError: Cannot read property 'params' of undefined
    at cloudFunction (/Users/mayurdhurpate/code/pruoo_app/backend_admin/functions/node_modules/firebase-functions/lib/cloud-functions.js:109:38)
    at Run (/Users/mayurdhurpate/.npm-global/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:458:20)
    at /Users/mayurdhurpate/.npm-global/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:442:19
    at Generator.next (<anonymous>)
    at /Users/mayurdhurpate/.npm-global/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/mayurdhurpate/.npm-global/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:3:12)
    at Run (/Users/mayurdhurpate/.npm-global/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:435:12)
    at /Users/mayurdhurpate/.npm-global/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:457:15
    at Generator.next (<anonymous>)
⚠  Your function was killed because it raised an unhandled error.

我想我可能缺少必填的params 字段,但我找不到输入参数的正确方法。我在 MacOS 上使用 firebase-tools@7.1.1

【问题讨论】:

    标签: firebase google-cloud-platform google-cloud-functions google-cloud-pubsub firebase-cli


    【解决方案1】:

    我有同样的错误。 错误位于 cloud-functions.js:117:28。

    即使上下文不存在,他也试图访问上下文的键。

    我更新到最新版本,但错误仍然存​​在。

    作为解决方法,我在 cloud-functions.js 的第 89 行添加了以下代码:context = context || {};

    这解决了错误,我可以使用 firebase shell。

    我希望这个讨厌的 hack 能有所帮助。 直到 Google 修复他们的代码或更新文档。

    多米尼克

    【讨论】:

    • 你在 GitHub 上提交过问题吗?
    • 嗨!不,我没有
    • 如果您在 Firebase CLI 中发现错误,请提交报告。这会很有帮助。 github.com/firebase/firebase-tools
    猜你喜欢
    • 2019-07-26
    • 2018-10-10
    • 2021-11-26
    • 2019-02-25
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    • 2018-06-22
    • 1970-01-01
    相关资源
    最近更新 更多