با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
اگر میخواهید عملکردها را برای اجرا در زمانهای مشخص زمانبندی کنید، از کنترلکننده onSchedule برای ایجاد یک موضوع Pub/Sub استفاده کنید که از Cloud Scheduler برای راهاندازی رویدادها در آن موضوع استفاده میکند.
قبل از شروع
اگرچه صورتحساب مورد نیاز است، میتوانید انتظار داشته باشید که هزینه کلی قابل مدیریت باشد، زیرا هر کار Cloud Scheduler 0.10 دلار (دلار آمریکا) در ماه هزینه دارد، و سه شغل برای هر حساب Google بدون هیچ هزینهای وجود دارد. از ماشین حساب قیمت گذاری Blaze برای ایجاد برآورد هزینه بر اساس استفاده پیش بینی شده خود استفاده کنید.
APIهای Pub/Sub و Cloud Scheduler باید برای پروژه شما فعال باشند. اینها قبلاً باید برای اکثر پروژه های Firebase فعال باشند. می توانید در کنسول Google Cloud تأیید کنید.
یک تابع زمان بندی شده بنویسید
در Cloud Functions for Firebase ، منطق زمانبندی در کد توابع شما قرار دارد، بدون نیاز به زمان استقرار خاص. برای ایجاد یک تابع زمان بندی شده، از functions.pubsub.schedule('your schedule').onRun((context)) استفاده کنید. به عنوان مثال، برای اجرای یک تابع هر پنج دقیقه با دستور App Engine cron.yaml ، این کار را انجام دهید:
exports.scheduledFunction=functions.pubsub.schedule('every 5 minutes').onRun((context)=>{functions.logger.log('This will be run every 5 minutes!');returnnull;});
هر دو یونیکس Crontab و App Engine توسط Cloud Scheduler پشتیبانی می شوند. به عنوان مثال، برای استفاده از Crontab برای انتخاب یک منطقه زمانی خاص که در آن یک تابع زمانبندی شده اجرا شود، این کار را انجام دهید:
exports.scheduledFunctionCrontab=functions.pubsub.schedule('5 11 * * *').timeZone('America/New_York')//Userscanchoosetimezone-defaultisAmerica/Los_Angeles.onRun((context)=>{functions.logger.log('This will be run every day at 11:05 AM Eastern!');returnnull;});
وقتی یک تابع زمانبندی شده را اجرا میکنید، کار زمانبندی مرتبط و موضوع میخانه/فرعی بهطور خودکار ایجاد میشود. Firebase CLI بازتاب نام موضوع است و میتوانید کار و موضوع را در کنسول Google Cloud مشاهده کنید. موضوع بر اساس قرارداد زیر نامگذاری شده است:
تاریخ آخرین بهروزرسانی 2025-09-04 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-09-04 بهوقت ساعت هماهنگ جهانی."],[],[],null,["\u003cbr /\u003e\n\n2nd gen 1st gen \n\n\u003cbr /\u003e\n\nIf you want to schedule functions to run at specified times, use\nthe `onSchedule` handler to create a\n[Pub/Sub](https://cloud.google.com/pubsub/) topic that uses\n[Cloud Scheduler](https://cloud.google.com/scheduler/) to trigger events on\nthat topic.\n\nBefore you begin\n\nThough billing is required, you can expect the overall cost to be manageable, as\neach Cloud Scheduler job costs $0.10 (USD) per month, and there is an\nallowance of three jobs per Google account, at no charge. Use the Blaze\n[pricing calculator](/pricing#blaze-calculator) to generate a cost estimate\nbased on your projected usage.\n\nThe Pub/Sub and Cloud Scheduler APIs must be enabled for your\nproject. These should already be enabled for most Firebase projects; you can\nverify in the [Google Cloud console](https://console.cloud.google.com/).\n| **Important:** Cloud Scheduler used to require that your project have a [Google App Engine app](https://cloud.google.com/appengine/docs/). During its setup you were prompted to select a location, and this location became your project's [*location for\n| default Google Cloud resources*](/docs/projects/locations#default-cloud-location) (Cloud Scheduler being one of these resources). This location is used for resources in your project that have an association with App Engine, including your *default* Cloud Firestore database instance and your *default* Cloud Storage bucket (specifically with the name format `*.appspot.com`).\n|\n| However, now that Cloud Scheduler and recently provisioned\n| default Cloud Storage buckets (with the name format\n| `*.firebasestorage.app`) no longer have a dependency\n| on App Engine, you only need to consider this location if you're using\n| 1st gen scheduled functions and `*.appspot.com`\n| buckets.\n\nWrite a scheduled function\n\nIn Cloud Functions for Firebase, scheduling logic resides in your functions code,\nwith no special deploy-time requirements. To create a scheduled function,\nuse `functions.pubsub.schedule('your schedule').onRun((context))`.\nFor example, to run a function every\nfive minutes with\n[App Engine cron.yaml](https://cloud.google.com/appengine/docs/standard/python/config/cronref)\nsyntax, do something like this: \n\n exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) =\u003e {\n functions.logger.log('This will be run every 5 minutes!');\n return null;\n });\n\nBoth Unix Crontab and App Engine syntax\nare supported by Cloud Scheduler. For example, to use Crontab to select a\nspecific timezone in which to run a scheduled function, do something like this: \n\n exports.scheduledFunctionCrontab = functions.pubsub.schedule('5 11 * * *')\n .timeZone('America/New_York') // Users can choose timezone - default is America/Los_Angeles\n .onRun((context) =\u003e {\n functions.logger.log('This will be run every day at 11:05 AM Eastern!');\n return null;\n });\n\nThe value for `timeZone` must be a time zone name from the\n[tz database](http://en.wikipedia.org/wiki/Tz_database). See the\n[Cloud Scheduler reference](https://cloud.google.com/scheduler/docs/reference/rpc/google.cloud.scheduler.v1#job)\nfor more information on supported properties.\n| **Important:** Depending on how you design your scheduling logic, a function may be triggered multiple times, with the next instance running while the previous instance is still executing.\n\nThe `context` object for a scheduled function includes information about the\nPub/Sub event that triggered it. For example: \n\n {\n \"resource\": {\n \"name\": \"projects/PROJECT_ID/topics/PROJECT_TOPIC\",\n \"service\": \"pubsub.googleapis.com\",\n \"type\": \"type.googleapis.com/google.pubsub.v1.PubsubMessage\"\n },\n \"timestamp\": \"YYYY-MM-DDTHH:MM:SS.sssZ\",\n \"eventType\": \"google.pubsub.topic.publish\",\n \"eventId\": \"EVENT_ID\",\n \"params\": {}\n }\n\nDeploy a scheduled function\n\nWhen you deploy a scheduled function, the related scheduler job and pub/sub\ntopic are created automatically. The Firebase CLI echoes the topic name,\nand you can view the job and topic in the\n[Google Cloud console](https://console.cloud.google.com/project/_/cloudscheduler).\nThe topic is named according to the following convention:\n\n**firebase-scheduled-\u003cvar translate=\"no\"\u003efunction_name\u003c/var\u003e-\u003cvar translate=\"no\"\u003eregion\u003c/var\u003e**\n\nFor example:\n\n**firebase-scheduled-scheduledFunctionCrontab-us-east1.**\n| **Important:** Make sure you do not manually delete or modify the topic or scheduler job in the console. Doing this could cause errors in the execution of your scheduled function."]]