عند إنشاء إضافة، يمكنك كتابة منطقها باستخدام دوال Cloud،
بالطريقة نفسها التي ستكتب بها دالة لن يتم استخدامها إلا في
لمشروعك الخاص. لقد أعلنت عن الدوال في ملف extension.yaml
عندما يثبّت المستخدمون الإضافة، يتم نشر هذه الدوال في
مشروعك.
راجِع مستندات دوال Cloud للحصول على معلومات عامة حول استخدام. وظائف السحابة الإلكترونية:
وظائف السحابة الإلكترونية من الجيل الأول والثاني
يتوافق Firebase مع كليهما وظائف السحابة الإلكترونية من الجيل الأول والجيل الثاني مع ذلك، يمكن لمنصة Firebase تخضع الإضافات حاليًا لبعض القيود على إنشاء السحابة الإلكترونية التي يمكنك استخدامها مع أنواع معينة من المشغلات. لهذا السبب، قد يفكر العديد تتضمن الإضافات مزيجًا من وظائف الجيل الأول والثاني.
تتم ملاحظة دعم إنشاء الدوال لكل نوع من أنواع المشغِّلات، أدناه.
اعتبارات خاصة
تتطلب منك بعض تعريفات الدوال تحديد معلومات المحدد في ملف
extension.yaml
. على سبيل المثال، تضم Cloud Firestoredocument()
التي تحدد نمط المستند المراد مشاهدته، يتضمن البيان المقابل فيextension.yaml
حقلresource
يحدد نفس الشيء.في هذه الحالات، سيتم ضبط الإعدادات المحدّدة في
extension.yaml
يتم استخدام الملف وتكون التهيئة المحددة في تعريف الدالة وتجاهل.من الشائع تحديد القيمة التي تم ضبطها في الدالة. بصرف النظر عن التعريف، من أجل التوثيق. الأمثلة على ذلك تتبع هذا النمط.
تستخدم حزمة تطوير البرامج (SDK) من الجيل الأول من Cloud Functions طريقة
functions.config()
functions:config:set
CLI الذي يمكنك استخدامه للعمل به القيم ذات المعلَمات في دوال الجيل الأول. تم إيقاف هذه التقنية نهائيًا في لن تعمل وظائف السحابة الإلكترونية على الإطلاق في أي إضافة. بدلاً من ذلك، استخدم وحدةfunctions.params
(يُنصح بها) أوprocess.env
.
استخدام TypeScript
تصف معظم مستندات تطوير الإضافة الخاصة بك مهام سير العمل. باستخدام JavaScript للوظائف السحابية لبرنامج Firebase. ومع ذلك، يمكنك بدلاً من ذلك كتابة الدوال باستخدام TypeScript.
في الواقع، جميع إضافات Firebase الرسمية المكتوبة بلغة TypeScript. يمكنك مراجعة هذه الإضافات للحصول على أفضل الممارسات لاستخدام TypeScript لإضافتك.
إذا كتبت دوال الإضافة باستخدام TypeScript، يجب تنفيذ الإجراء التالي: قبل تثبيت الإضافة:
جمِّع رمز المصدر لدوال الإضافة إلى JavaScript.
يعمل
firebase ext:dev:init
الأمر تسمح لك باختيار TypeScript لكتابة الدوال. الأمر إضافة كاملة وقابلة للتثبيت بالإضافة إلى توفير نص برمجي يمكنك تشغيله باستخدامnpm run build
.في ملف
package.json
، تأكَّد من توجيه الحقلmain
إلى التي تم إنشاؤها باستخدام JavaScript.إذا كنت تثبّت إضافتك أو تحمّلها من مصدر محلي تجميع ملفات TypeScript أولاً.
عوامل تشغيل الدوال المتوافقة
مشغلات HTTP
يتم تفعيل دالة يتم تشغيلها عبر HTTP في نقطة نهاية https
عامة ويتم تشغيلها
عند الوصول إلى نقطة النهاية.
اطّلِع على وظائف الاتصال من خلال طلبات HTTP في دوال السحابة الإلكترونية. وثائق لمعلومات حول كتابة الدوال التي يشغّلها HTTP.
تعريف الدالة (الجيل الأول فقط)
import { https } from "firebase-functions/v1";
export const yourFunctionName = https.onRequest(async (req, resp) => {
// ...
});
بيان المورد (extension.yaml)
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
runtime: nodejs16
httpsTrigger: {}
- name: anotherFunction
type: ...
الدوال القابلة للاستدعاء
تشبه الدوال القابلة للاستدعاء الدوال التي يتم تشغيلها عبر HTTP، ولكنها تنفّذ بروتوكول يسهِّل الاتصال من خلال الرمز من جهة العميل.
الاطّلاع على وظائف الاتصال من تطبيقك في مستندات Cloud Functions للحصول على معلومات حول استخدام الدوال القابلة للاستدعاء.
تعريف الدالة (الجيل الأول فقط)
import { https } from "firebase-functions/v1";
export const yourFunctionName = https.onCall(async (data, context) => {
// ...
});
بيان المورد (extension.yaml)
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
runtime: nodejs16
httpsTrigger: {}
- name: anotherFunction
type: ...
عوامل تشغيل الدوال المجدوَلة
يتم تشغيل الدالة المُجدوَلة بشكل متكرّر استنادًا إلى جدول زمني قابل للتخصيص.
يمكنك الاطّلاع على دوال الجدولة في مستندات دوال السحابة الإلكترونية للتعرّف على معلومات حول كتابة الدوال المجدولة.
تعريف الدالة (الجيل الأول فقط)
import { pubsub } from "firebase-functions/v1";
export const yourFunctionName = pubsub.schedule("every 6 hours").onRun((context) => {
// ...
});
بيان المورد (extension.yaml)
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
scheduleTrigger:
schedule: 'every 5 minutes'
- name: anotherFunction
type: ...
في ما يلي الحقول الفرعية المتاحة لـ scheduleTrigger
:
الحقل | الوصف |
---|---|
schedule (مطلوب) |
التكرار الذي تريد تشغيل الدالة به. يمكن لهذا الحقل قبول السلاسل التي تستخدم أي من بناء الجملة (الالتفاف في علامات الاقتباس المفردة مطلوبة):
|
timeZone (اختياري) |
المنطقة الزمنية التي سيتم تنفيذ الجدول الزمني فيها.
|
إذا أردت أن يتمكن المستخدمون من تهيئة الجدول الزمني عند تثبيت
تضيف معلمة جديدة إلى ملف extension.yaml
والإشارة إلى
في بيان resource
للدالة:
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
scheduleTrigger:
schedule: ${SCHEDULE_FREQUENCY}
- name: anotherFunction
type: ...
params:
- param: SCHEDULE_FREQUENCY
label: Schedule
description: How often do you want to run yourFunctionName()?
type: string
default: 'every 5 minutes' # Specifying a default is optional.
required: true
مشغِّلات قائمة المهام
يتم تشغيل وظيفة قائمة المهام إما خلال دورة حياة الإضافة
الأحداث أو عند إضافتها يدويًا إلى قائمة انتظار مهام الإضافة باستخدام وحدة تحكّم المشرف
طريقة TaskQueue.enqueue()
في حزمة تطوير البرامج (SDK)
راجِع التعامل مع أحداث مراحل نشاط الإضافة للحصول على معلومات حول الكتابة. الدوال التي تتعامل مع أحداث مراحل النشاط.
يُرجى الاطّلاع على إدراج الدوال في قائمة الانتظار مع "مهام Cloud" في دوال السحابة الإلكترونية. وثائق للحصول على معلومات حول كتابة دوال قائمة انتظار المهام.
تعريف الدالة (الجيل الأول فقط)
import { tasks } from "firebase-functions/v1";
export const yourFunctionName = tasks.taskQueue().onDispatch(async (data, context) => {
// ...
});
بيان المورد (extension.yaml)
resources:
- name: myTaskFunction
type: firebaseextensions.v1beta.function
description: >-
Perform a task when triggered by a lifecycle event
properties:
taskQueueTrigger: {}
يمكنك ضبط السمة taskQueueTrigger
على {}
أو على خريطة خيارات
ضبط حدود المعدل وإعادة محاولة سلوك قائمة انتظار المهام (راجع ضبط المهمة
قائمة الانتظار).
إذا كنت تريد تشغيل الدالة خلال أحداث مراحل نشاط الإضافة، أضِف
سجلات lifecycleEvents
باسم الدالة والحقل الاختياري
قيد المعالجة، والتي سيتم عرضها في وحدة تحكُّم Firebase
تبدأ المعالجة.
lifecycleEvents:
onInstall:
function: myTaskFunction
processingMessage: Resizing your existing images
onUpdate:
function: myOtherTaskFunction
processingMessage: Setting up your extension
onConfigure:
function: myOtherTaskFunction
processingMessage: Setting up your extension
إحصاءات Google
يتم تشغيل دالة يتم تشغيلها في "إحصاءات Google" عند إجراء حدث معيّن في "إحصاءات Google" تسجيل.
اطّلِع على مشغّلات "إحصاءات Google" في مستندات Cloud Functions عن المقالة. معلومات حول كتابة الدوال التي يتم تشغيلها في Analytics.
تعريف الدالة (الجيل الأول فقط)
import { analytics } from "firebase-functions/v1";
export const yourFunctionName = analytics.event("event_name").onLog((event, context) => {
// ...
});
بيان المورد (extension.yaml)
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
eventTrigger:
eventType: providers/google.firebase.analytics/eventTypes/event.log
resource: projects/${PROJECT_ID}/events/ga_event
- name: anotherFunction
type: ...
إذا أردت أن يتمكّن المستخدِمون من ضبط حدث "إحصاءات Google" للاستماع إلى
أضِف مَعلمة جديدة إلى extension.yaml
عند تثبيت الإضافة
والإشارة إلى المعلمة في بيان resource
للدالة:
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
eventTrigger:
eventType: providers/google.firebase.analytics/eventTypes/event.log
resource: projects/${PROJECT_ID}/events/${EVENT_NAME}
- name: anotherFunction
type: ...
params:
- param: EVENT_NAME
label: Analytics event
description: What event do you want to respond to?
type: string
default: ga_event # Specifying a default is optional.
required: true
المصادقة
تعمل الدالة التي تشغِّل المصادقة عند إنشاء مستخدم أو حذفه.
الاطّلاع على مشغلات مصادقة Firebase في دوال السحابة مستندات لمزيد من المعلومات حول كتابة الدوال التي تتم المصادقة عليها.
تعريف الدالة (الجيل الأول فقط)
import { auth } from "firebase-functions/v1";
export const yourFunctionName = auth.user().onCreate((user, context) => {
// ...
});
export const yourFunctionName2 = auth.user().onDelete((user, context) => {
// ...
});
بيان المورد (extension.yaml)
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
eventTrigger:
eventType: providers/firebase.auth/eventTypes/user.create
resource: projects/${PROJECT_ID}
- name: anotherFunction
type: ...
يوضّح الجدول التالي كيفية تحديد كل حدث من أحداث المصادقة المتوافقة. الأنواع:
مشغِّل حدث Cloud Functions | eventType |
الوصف |
---|---|---|
onCreate() |
providers/firebase.auth/eventTypes/user.create |
تم إنشاء مستخدم جديد |
onDelete() |
providers/firebase.auth/eventTypes/user.delete |
تم حذف المستخدم. |
Cloud Firestore
يتم تشغيل الدالة التي يتم تشغيلها في Cloud Firestore عند إنشاء مستند أو تحديثه أو حذفها.
يُرجى الاطّلاع على مشغلات Cloud Firestore في مستندات "دوال Cloud" للتعرّف على معلومات حول كتابة الدوال التي يتم تشغيلها في Firestore.
تعريف الدالة (الجيل الأول فقط)
import { firestore } from "firebase-functions/v1";
export const yourFunctionName = firestore.document("collection/{doc_id}")
.onCreate((snapshot, context) => {
// ...
});
export const yourFunctionName2 = firestore.document("collection/{doc_id}")
.onUpdate((change, context) => {
// ...
});
export const yourFunctionName3 = firestore.document("collection/{doc_id}")
.onDelete((snapshot, context) => {
// ...
});
export const yourFunctionName4 = firestore.document("collection/{doc_id}")
.onWrite((change, context) => {
// onWrite triggers on creation, update, and deletion.
// ...
});
بيان المورد (extension.yaml)
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
eventTrigger:
eventType: providers/cloud.firestore/eventTypes/document.write
resource: projects/${PROJECT_ID}/databases/(default)/documents/collection/{documentID}
- name: anotherFunction
type: ...
يوضّح الجدول التالي كيفية تحديد كل من Cloud Firestore المتوافق أنواع الأحداث:
مشغِّل حدث Cloud Functions | eventType |
الوصف |
---|---|---|
onCreate() |
providers/cloud.firestore/eventTypes/document.create |
تم إنشاء مستند جديد. |
onDelete() |
providers/cloud.firestore/eventTypes/document.delete |
تم حذف المستند. |
onUpdate() |
providers/cloud.firestore/eventTypes/document.update |
تم تعديل المستند. |
onWrite() |
providers/cloud.firestore/eventTypes/document.write |
تم إنشاء المستند أو حذفه أو تعديله. |
إذا أردت أن يتمكن المستخدمون من ضبط مسار المستند عند التثبيت
إضافتك، وإضافة معلمة جديدة إلى ملف extension.yaml
والإشارة إلى
المعلمة في بيان resource
للدالة:
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
eventTrigger:
eventType: providers/cloud.firestore/eventTypes/document.write
resource: projects/${PROJECT_ID}/databases/(default)/documents/${YOUR_DOCUMENT_PATH}
- name: anotherFunction
type: ...
params:
- param: YOUR_DOCUMENT_PATH
label: Cloud Firestore path
description: Where do you want to watch for changes?
type: string
default: path/to/{documentID} # Specifying a default is optional.
required: true
نشر/اشتراك
تعمل الدالة Pub/Sub-قيد التشغيل عند نشر رسالة إلى مجموعة الموضوع.
اطّلِع على مشغلات النشر/الاشتراك في مستندات Cloud Functions للتعرّف على معلومات حول كتابة الدوال Pub/Sub تُشغَّل.
تعريف الدالة (الجيل الأول فقط)
import { pubsub } from "firebase-functions/v1";
export const yourFunctionName = pubsub.topic("topic_name").onPublish((message, context) => {
// ...
});
بيان المورد (extension.yaml)
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
eventTrigger:
eventType: google.pubsub.topic.publish
resource: projects/${PROJECT_ID}/topics/topic-name
- name: anotherFunction
type: ...
إذا أردت أن يتمكن المستخدمون من ضبط موضوع النشر/الاشتراك عند
يثبتون إضافتك، ويضيفون معلَمة جديدة إلى ملف extension.yaml
.
والإشارة إلى المَعلمة في بيان resource
للدالة:
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
eventTrigger:
eventType: google.pubsub.topic.publish
resource: projects/${PROJECT_ID}/topics/${PUBSUB_TOPIC}
- name: anotherFunction
type: ...
params:
- param: PUBSUB_TOPIC
label: Pub/Sub topic
description: Which Pub/Sub topic do you want to watch for messages?
type: string
default: topic-name # Specifying a default is optional.
required: true
قاعدة بيانات الوقت الفعلي
يتم تشغيل الدالة التي يتم تشغيلها في قاعدة البيانات في الوقت الفعلي عندما يتطابق مسار مع مسار محدد يتم إنشاء نمط أو تحديثه أو حذفه.
اطّلِع على عوامل تشغيل قاعدة البيانات في الوقت الفعلي في مستندات Cloud Functions. للحصول على معلومات حول كتابة الدوال التي يشغّلها RTDB.
تعريف الدالة (الجيل الأول فقط)
import { database } from "firebase-functions/v1";
export const yourFunctionName = database.ref("path/to/{item}")
.onCreate((snapshot, context) => {
// ...
});
export const yourFunctionName2 = database.ref("path/to/{item}")
.onUpdate((change, context) => {
// ...
});
export const yourFunctionName3 = database.ref("path/to/{item}")
.onDelete((snapshot, context) => {
// ...
});
export const yourFunctionName4 = database.ref("path/to/{item}")
.onWrite((change, context) => {
// onWrite triggers on creation, update, and deletion.
// ...
});
بيان المورد (extension.yaml)
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
eventTrigger:
eventType: providers/google.firebase.database/eventTypes/ref.create
# DATABASE_INSTANCE (project's default instance) is an auto-populated
# parameter value. You can also specify an instance.
resource: projects/_/instances/${DATABASE_INSTANCE}/refs/path/to/{itemId}
- name: anotherFunction
type: ...
يوضّح الجدول التالي كيفية تحديد كل من Cloud Firestore المتوافق أنواع الأحداث:
مشغِّل حدث Cloud Functions | eventType |
الوصف |
---|---|---|
onCreate() |
providers/google.firebase.database/eventTypes/ref.create |
تم إنشاء البيانات |
onDelete() |
providers/google.firebase.database/eventTypes/ref.delete |
تم حذف البيانات |
onUpdate() |
providers/google.firebase.database/eventTypes/ref.update |
تم تعديل البيانات. |
onWrite() |
providers/google.firebase.database/eventTypes/ref.write |
البيانات التي تم إنشاؤها أو حذفها أو تعديلها |
إذا أردت أن يتمكّن المستخدمون من ضبط المسار الذي تريد مشاهدته عند تثبيته
إضافتك، وإضافة معلمة جديدة إلى ملف extension.yaml
والإشارة إلى
المعلمة في بيان resource
للدالة:
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
eventTrigger:
eventType: providers/google.firebase.database/eventTypes/ref.create
# DATABASE_INSTANCE (project's default instance) is an auto-populated
# parameter value. You can also specify an instance.
resource: projects/_/instances/${DATABASE_INSTANCE}/refs/${DB_PATH}
- name: anotherFunction
type: ...
params:
- param: DB_PATH
label: Realtime Database path
description: Where do you want to watch for changes?
type: string
default: path/to/{itemId} # Specifying a default is optional.
required: true
الإعداد عن بُعد
يتم تشغيل الدالة التي يتم تشغيلها عن بُعد عندما يكون نموذج معلَمة المشروع تحديث.
راجِع مشغلات الإعداد عن بُعد في مستندات "دوال السحابة الإلكترونية" للتعرّف على معلومات حول كتابة الدوال المُشغّلة في ميزة "الإعداد عن بُعد".
تعريف الدالة (الجيل الأول فقط)
import { remoteConfig } from "firebase-functions/v1";
export const yourFunctionName = remoteConfig.onUpdate((version, context) => {
// ...
});
بيان المورد (extension.yaml)
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
eventTrigger:
eventType: google.firebase.remoteconfig.update
resource: projects/${PROJECT_ID}
- name: anotherFunction
type: ...
Cloud Storage
يتم تشغيل الدالة التي يتم تشغيلها في Cloud Storage عند إنشاء عنصر أو أرشفته أو أو عند تغيير بياناتها الوصفية.
اطّلِع على عوامل التشغيل في Cloud Storage في مستندات "دوال Cloud" للتعرّف على معلومات حول كتابة الدوال التي يتم تشغيلها في التخزين.
تعريف الدالة (الجيل الأول فقط)
import { storage } from "firebase-functions/v1";
export const yourFunctionName = storage.object().onFinalize((object, context) => {
// ...
});
export const yourFunctionName2 = storage.object().onMetadataUpdate((object, context) => {
// ...
});
export const yourFunctionName3 = storage.object().onArchive((object, context) => {
// ...
});
export const yourFunctionName4 = storage.object().onDelete((object, context) => {
// ...
});
بيان المورد (extension.yaml)
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
eventTrigger:
eventType: google.storage.object.finalize
# STORAGE_BUCKET (project's default bucket) is an auto-populated
# parameter. You can also specify a bucket.
resource: projects/_/buckets/${STORAGE_BUCKET}
- name: anotherFunction
type: ...
يعرض الجدول التالي كيفية تحديد كل مساحة تخزين سحابية متوافقة. أنواع الأحداث:
مشغِّل حدث Cloud Functions | eventType |
الوصف |
---|---|---|
onFinalize() |
google.storage.object.finalize |
تم إنشاء العنصر |
onMetadataUpdate() |
google.storage.object.metadataUpdate |
تم تعديل البيانات الوصفية للعنصر. |
onArchive() |
google.storage.object.archive |
تمت أرشفة العنصر |
onDelete() |
google.storage.object.delete |
تم حذف العنصر |
إذا أردت أن يتمكّن المستخدمون من ضبط حزمة التخزين عند تثبيتها
إضافتك، وإضافة معلمة جديدة إلى ملف extension.yaml
والإشارة إلى
المعلمة في بيان resource
للدالة:
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
eventTrigger:
eventType: google.storage.object.finalize
resource: projects/_/buckets/${YOUR_BUCKET}
- name: anotherFunction
type: ...
params:
- param: YOUR_BUCKET
label: Cloud Storage bucket
description: Which bucket do you want to watch for changes?
type: selectResource
resourceType: storage.googleapis.com/Bucket
default: ${STORAGE_BUCKET} # Specifying a default is optional.
required: true
مركز الاختبار الافتراضي
يتم تشغيل دالة يتم تشغيلها في مركز الاختبار الافتراضي عندما تنتهي مصفوفة الاختبار من اختباراتها.
الاطّلاع على مشغلات Firebase Test Lab في مستندات Cloud Functions للحصول على معلومات حول كتابة الدوال التي يشغّلها مركز الاختبار.
تعريف الدالة (الجيل الأول فقط)
import { testLab } from "firebase-functions/v1";
export const yourFunctionName = testLab.testMatrix().onComplete((matrix, context) => {
// ...
});
بيان المورد (extension.yaml)
resources:
- name: yourFunctionName
type: firebaseextensions.v1beta.function
properties:
eventTrigger:
eventType: google.testing.testMatrix.complete
resource: projects/${PROJECT_ID}/testMatrices/{matrixId}
- name: anotherFunction
type: ...
عوامل تشغيل تنبيه Crashlytics
يتم تشغيل الدالة التي يتم تشغيلها Crashlytics عندما ينشر Crashlytics تنبيه.
الاطّلاع على مشغّلات تنبيهات Firebase في مستندات دوال السحابة الإلكترونية معلومات حول كتابة الدوال التي تثير التنبيهات.
تعريف الدالة (الجيل الثاني فقط)
import {
onNewFatalIssuePublished,
onNewNonfatalIssuePublished,
onNewAnrIssuePublished,
onRegressionAlertPublished,
onVelocityAlertPublished,
onStabilityDigestPublished,
} from "firebase-functions/v2/alerts/crashlytics";
export const yourFunctionName = onNewFatalIssuePublished((event) => {
// ...
});
export const yourFunctionName2 = onNewNonfatalIssuePublished((event) => {
// ...
});
export const yourFunctionName3 = onNewAnrIssuePublished((event) => {
// ...
});
export const yourFunctionName4 = onRegressionAlertPublished((event) => {
// ...
});
export const yourFunctionName5 = onVelocityAlertPublished((event) => {
// ...
});
export const yourFunctionName6 = onStabilityDigestPublished((event) => {
// ...
});
بيان المورد (extension.yaml)
apis:
- apiName: eventarc.googleapis.com
reason: Powers all events and triggers
- apiName: run.googleapis.com
reason: Powers 2nd-gen functions
resources:
- name: yourfunctionname
type: firebaseextensions.v1beta.v2function
properties:
buildConfig:
runtime: nodejs16
serviceConfig:
availableMemory: 512M
eventTrigger:
eventType: google.firebase.firebasealerts.alerts.v1.published
triggerRegion: global
eventFilters:
- attribute: alerttype
value: crashlytics.newFatalIssue
- name: anotherFunction
type: ...
يمكنك استخدام القيم التالية: alerttype
crashlytics.newFatalIssue
crashlytics.newNonfatalIssue
crashlytics.regression
crashlytics.stabilityDigest
crashlytics.velocity
crashlytics.newAnrIssue
عوامل تشغيل تنبيه مراقبة الأداء
يتم تشغيل وظيفة يتم تشغيلها من خلال "مراقبة الأداء" عندما تنشر "مراقبة الأداء" تنبيهًا.
الاطّلاع على مشغّلات تنبيهات Firebase في مستندات دوال السحابة الإلكترونية معلومات حول كتابة الدوال التي تثير التنبيهات.
تعريف الدالة (الجيل الثاني فقط)
import { onThresholdAlertPublished } from "firebase-functions/v2/alerts/performance";
export const yourFunctionName = onThresholdAlertPublished((event) => {
// ...
});
بيان المورد (extension.yaml)
apis:
- apiName: eventarc.googleapis.com
reason: Powers all events and triggers
- apiName: run.googleapis.com
reason: Powers 2nd-gen functions
resources:
- name: yourfunctionname
type: firebaseextensions.v1beta.v2function
properties:
buildConfig:
runtime: nodejs16
serviceConfig:
availableMemory: 512M
eventTrigger:
eventType: google.firebase.firebasealerts.alerts.v1.published
triggerRegion: global
eventFilters:
- attribute: alerttype
value: performance.threshold
- name: anotherFunction
type: ...
عوامل تشغيل تنبيه "توزيع التطبيقات"
يتم تشغيل دالة يتم تشغيلها عند نشر ميزة App Distribution لتنبيه.
الاطّلاع على مشغّلات تنبيهات Firebase في مستندات دوال السحابة الإلكترونية معلومات حول كتابة الدوال التي تثير التنبيهات.
تعريف الدالة (الجيل الثاني فقط)
import {
onNewTesterIosDevicePublished,
onInAppFeedbackPublished
} from "firebase-functions/v2/alerts/appDistribution";
export const yourFunctionName = onNewTesterIosDevicePublished((event) => {
// ...
});
export const yourFunctionName2 = onInAppFeedbackPublished((event) => {
// ...
});
بيان المورد (extension.yaml)
apis:
- apiName: eventarc.googleapis.com
reason: Powers all events and triggers
- apiName: run.googleapis.com
reason: Powers 2nd-gen functions
resources:
- name: yourfunctionname
type: firebaseextensions.v1beta.v2function
properties:
buildConfig:
runtime: nodejs16
serviceConfig:
availableMemory: 512M
eventTrigger:
eventType: google.firebase.firebasealerts.alerts.v1.published
triggerRegion: global
eventFilters:
- attribute: alerttype
value: appDistribution.inAppFeedback
- name: anotherFunction
type: ...
يمكنك استخدام القيم التالية: alerttype
appDistribution.newTesterIosDevice
appDistribution.inAppFeedback
عوامل تشغيل الأحداث المخصّصة (Eventarc)
تعمل الدالة التي يتم تشغيلها Eventarc عند نشر نوع حدث معين إلى قناة محددة.
الاطّلاع على إنشاء عوامل تشغيل الأحداث المخصّصة والتعامل معها في دوال Cloud للحصول على معلومات حول كتابة الدوال التي تُشغّلها Eventarc.
يمكنك أيضًا نشر أحداث من الإضافات لمنح المستخدمين طريقة لإدراجها. منطق مخصص في إضافتك. راجِع استخدام المنطق المخصّص الذي قدّمه المطوّر في الإضافة.
تعريف الدالة (الجيل الثاني فقط)
import { onCustomEventPublished } from "firebase-functions/v2/eventarc";
export const yourFunctionName = onCustomEventPublished((event) => {
// ...
});
بيان المورد (extension.yaml)
apis:
- apiName: eventarc.googleapis.com
reason: Powers all events and triggers
- apiName: run.googleapis.com
reason: Powers 2nd-gen functions
resources:
- name: yourfunctionname
type: firebaseextensions.v1beta.v2function
properties:
# LOCATION is a user-configured parameter value specified by the user
# during installation.
location: ${param:LOCATION}
buildConfig:
runtime: nodejs16
serviceConfig:
availableMemory: 512M
timeoutSeconds: 60
eventTrigger:
eventType: firebase.extensions.storage-resize-images.v1.complete
channel: projects/${param:PROJECT_ID}/locations/us-central1/channels/firebase
- name: anotherFunction
type: ...
يجب أن تكون القناة متوفّرة بعد تثبيت الإضافة. على سبيل المثال، إذا تعتمد على أحداث مخصصة من إضافة أخرى تنشئ القناة إرشاد المستخدمين لتثبيت هذه الإضافة أولاً.
سيؤدي المثال أعلاه إلى إنشاء عامل تشغيل حدث مخصّص للخيار "تلقائي" الإعداد عن بُعد
قناة في منطقة واحدة (us-central1
) يمكنك تغيير اسم القناة والمنطقة.
قابلة للتخصيص باستخدام المعلمات. على سبيل المثال:
params:
- param: EVENTARC_CHANNEL_NAME
label: Eventarc channel name
description: What is the name of the Eventarc channel.
default: firebase
type: string
required: true
resources:
- name: yourfunctionname
type: firebaseextensions.v1beta.v2function
properties:
location: ${param:LOCATION}
eventTrigger:
eventType: firebase.extensions.storage-resize-images.v1.complete
channel: projects/${param:PROJECT_ID}/locations/${param:LOCATION}/channels/${param:EVENTARC_CHANNEL_NAME}