firebase 云函数 v2 - 未部署自定义事件触发器

问题描述 投票:0回答:3

我正在尝试按照本指南https://firebase.google.com/docs/functions/beta/custom-events添加v2云函数来处理firebase stripe扩展提供的自定义事件。部署命令似乎运行没有错误,但我的新功能没有出现在云控制台中。

我的 firebase cli 版本是 10.2.1

我使用

const functionsV2 = require("firebase-functions/v2");

导入 FunctionsV2

我的函数签名是这样的

exports.stripetrialupdated = functionsV2
    .eventarc
    .onCustomEventPublished(
        {
          eventType: "com.stripe.v1.customer.subscription.updated",
          channel:
          "projects/success-academy-5eed2/locations/us-west1/channels/firebase",
          region: "us-west1",
        },
        (event) => {...});

但是,当我尝试使用

firebase deploy --only functions
进行部署时,除此之外的所有功能都已部署。我的其他功能是 HTTP 触发器并且部署良好,并且所有功能都在同一个 index.js 文件中。没有错误消息,只是该函数没有出现在部署命令输出中。另外,运行
firebase deploy --only functions:stripetrialupdated
会导致

i  deploying functions
Running command: npm --prefix functions run lint

> functions@ lint /Users/gmiao/workspace/success-academy-5eed2/functions
> eslint .

✔  functions: Finished running predeploy script.
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔  functions: required API cloudfunctions.googleapis.com is enabled
✔  functions: required API cloudbuild.googleapis.com is enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (82.12 KB) for uploading
✔  functions: functions folder uploaded successfully
i  functions: cleaning up build files...

✔  Deploy complete!
node.js firebase google-cloud-functions firebase-extensions
3个回答
0
投票

我仍然不使用版本 2,因为它最近才发布,但是否由于您正在记录自定义事件,它们不会出现在控制台中但仍然存在? 您是否尝试过输入 console.log(“调用”)在某处? 这可能是一个愚蠢的问题,但我问你是因为你没有在问题中写下它。 另外,加载函数后云函数控制台显示什么?


0
投票

感谢您的建议,但我最终只是直接处理 stripe http webhook 事件,而不是使用 eventarc 触发器。

https://medium.com/@GaryHarrower/working-with-stripe-webhooks-firebase-cloud-functions-5366c206c6c


0
投票

我遇到了完全相同的问题,我不明白为什么我无法在记录器中获取事件,并且令我惊讶的是我无法将任何 onCustomEventPublished 函数部署到 Cloud Functions。

解决方案是确保您使用最新版本的 Firebase CLI。您可以通过在终端中运行 firebase --version 来检查版本。如果您不是最新版本,请考虑使用 npm install -g firebase-tools 进行升级。

这为我解决了这个问题,现在我可以看到在“函数”选项卡中创建了以下触发器:

exports.onresized = onCustomEventPublished(
    'firebase.extensions.storage-resize-images.v1.onSuccess',
    (event) => {console.log('WORKING!!! :D')
        functions.logger.info('Resize Image is successful', event);
        // Additional operations based on the event data can be performed here
        return Promise.resolve();
    },
);
© www.soinside.com 2019 - 2024. All rights reserved.