지정된 시간에 함수를 실행하도록 예약하려면 onSchedule 핸들러를 사용하여 Cloud Scheduler를 통해 해당 주제의 이벤트를 트리거하는 Pub/Sub 주제를 만듭니다.
시작하기 전에
Firebase 프로젝트에서 이 솔루션을 사용하려면 프로젝트에서 Blaze 요금제를 사용해야 합니다. Blaze 요금제를 아직 사용하고 있지 않다면 요금제를 업그레이드하세요.
결제는 필수지만 각 Cloud Scheduler 작업의 월별 비용은 $0.10(USD)이고 Google 계정당 작업이 3개까지 무료로 허용되므로 전반적인 비용은 부담스럽지 않은 수준일 것입니다. Blaze 가격 계산기를 사용하여 예상 사용량에 따른 예상 비용을 확인해 보세요.
프로젝트에 Pub/Sub 및 Cloud Scheduler API를 사용 설정해야 합니다. 대부분의 Firebase 프로젝트에는 이미 사용 설정되어 있어야 하며 Google Cloud 콘솔에서 사용 설정 여부를 확인할 수 있습니다.
예약 함수 작성
Cloud Functions for Firebase에서 일정 예약 로직은 별다른 배포 시간 요구사항 없이 함수 코드에 상주하고 있습니다. 예약된 함수를 만들려면 functions.pubsub.schedule('your schedule').onRun((context))을 사용합니다.
예를 들어 App Engine cron.yaml 구문을 사용하여 5분마다 함수를 실행하려면 다음과 같이 작성하면 됩니다.
exports.scheduledFunction=functions.pubsub.schedule('every 5 minutes').onRun((context)=>{console.log('This will be run every 5 minutes!');returnnull;});
Unix Crontab 및 App Engine 구문은 모두 Cloud Scheduler에서 지원됩니다. 예를 들어 Crontab을 사용하여 예약 함수를 실행할 특정 시간대를 선택하려면 다음과 같이 작성하면 됩니다.
exports.scheduledFunctionCrontab=functions.pubsub.schedule('5 11 * * *').timeZone('America/New_York')//Userscanchoosetimezone-defaultisAmerica/Los_Angeles.onRun((context)=>{console.log('This will be run every day at 11:05 AM Eastern!');returnnull;});
[null,null,["최종 업데이트: 2025-08-17(UTC)"],[],[],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\nTo use this solution in your Firebase project, your project must be on the\nBlaze pricing plan. If it's not already on the Blaze plan,\n[upgrade your pricing plan](/pricing).\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 console.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 console.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\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."]]