Firestore 云功能 |基于时间字段的触发事件等于 [英] Firestore Cloud functions | trigger events based on time field is equal to

查看:33
本文介绍了Firestore 云功能 |基于时间字段的触发事件等于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当字段在特定持续时间内满足特定值时,您能否触发 Firebase 云函数?

Can you fire a firebase cloud function when a fields meet certain values for a specific amount of duration?

我构建了一个温度传感器应用程序,用户可以使用它来监控物体的温度.在某些情况下,如果温度在特定时间内达到特定水平,用户会希望收到通知.

I have built a temperature sensor application that users can use to monitor the temperature of an object. There are situations where users will want to be notified if the temperature hits a certain level for a specific amount of time.

我成功地获得了一个云函数,以便在字段更改时通过 twilio 发送文本,但现在我想插入更一致的业务规则.

I am successful in getting a cloud function to send the text via twilio when a field changes, but now I want to insert better-aligned business rules.

  • 传感器是否通电?
  • 温度是否大于x"?
  • 温度是否在x"以上的时间超过y"?

如果这些条件成立,我想发送一条短信.

If these conditions are true I want to send a text message.

我正在尝试确定最佳触发器,我可以在温度变化或传感器打开时简单地触发该功能,但这些云功能将无限期运行,直到永远不会触发.

I am trying to identify the best trigger, I could simply fire the function when the temperature changes or when the sensor is turned on, but these cloud functions will run indefinitely until the triggers which could be never.

我试图了解 Firebase 的计费规则,但我无法确定运行云功能是否会增加基于时间的计费.我不想解雇这个功能并在路上得到一笔大额账单.

I have tried to understand the billing rules with firebase, but I couldn't pinpoint if running cloud functions would increase billing based on time. I would hate to fire this function and get a major bill down the road.

推荐答案

目前,您无法限制触发事件的特定条件.您的 Firestore 触发器将针对符合触发器一般标准的每项更改接收一个事件.因此,对于 onUpdate 触发器,对符合一般条件(文档路径)的文档所做的任何更改都将触发该触发器.您无法选择哪些文档属性可以调用您的函数.您必须在函数内部检查它是否是您想要响应的事件,如果您不想对它做任何事情,请尽早返回.

Currently, you can't limit the specific conditions under which an event fires. Your Firestore trigger will receive one event for each change that meets the general criteria of the trigger. So, for onUpdate triggers, any change to a document that matches the general criteria (the document path) will fire that trigger. You can't be selective about which document properties may invoke your function. You have to check inside the function if it's an event you'd like to respond to, and return early if you don't want to do anything with it.

这篇关于Firestore 云功能 |基于时间字段的触发事件等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆