官术网_书友最值得收藏!

How does it work?

Once you write and deploy a function, Google's servers start listening to those functions immediately, that is listening for events and running the function when it gets triggered. As the load of your app increases or decreases, it responds by rapidly scaling the number of virtual server instances needed to run your function faster. If the function is deleted, idle, or updated by you, then instances are cleaned up and replaced by new instances. In the case of deletion, it also removes the connection between functions and the event provider.

Given here are the events that are supported by Cloud Functions:

  • onWrite(): It triggers when data is created, destroyed, or changed in the Realtime Database
  • onCreate(): It triggers when new data is created in the Realtime Database
  • onUpdate(): It triggers when data is updated in the Realtime Database
  • onDelete(): It triggers when data is deleted from the Realtime Database

Here's a code sample of the cloud function makeUppercase:

exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
.onWrite(event => {
// Grab the current value of what was written to the Realtime Database.
const original = event.data.val();
console.log('Uppercasing', event.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return event.data.ref.parent.child('uppercase').set(uppercase);
});
After you write the cloud function, we can also test and monitor our functions.
主站蜘蛛池模板: 宜章县| 南召县| 沁源县| 曲阳县| 宁乡县| 乐安县| 沿河| 慈利县| 六枝特区| 北京市| 翁源县| 红原县| 云林县| 乌兰浩特市| 静海县| 博野县| 塔城市| 皋兰县| 阿坝| 宁陕县| 西乡县| 泸水县| 惠来县| 鄂尔多斯市| 集安市| 澎湖县| 台东市| 旬阳县| 安化县| 利川市| 合水县| 壶关县| 崇阳县| 阿合奇县| 观塘区| 黔西县| 当雄县| 钟祥市| 三河市| 电白县| 白山市|