[GCP] Firebase Scheduler를 로컬에서 돌리기

He SEO·2022년 3월 14일
0

Firebase Scheduler를 개발할 때 로컬의 emulator로는 crontab 기능을 제대로 확인할 수 없습니다. 그래서 setInterval 기능을 사용하여 pub/sub 메시지를 수동으로 트리거 걸도록 합니다.

1. Scheduler 생성

import * as functions from "firebase-functions"

export const testCron = functions.region("asia-northeast3")
	.pubsub.schedule("every 1 minutes")
	.timeZone("Asia/Seoul")
	.onRun(async (content) => {
      console.log("run scheudler")
}

2. emulator 실행

firebase emulators:start

에뮬레이터가 구동이 되고 scheduler는 pub/sub 메시지를 수신할 수 있는 상태가 됩니다.

3. shell 실행

firebase functions:shell

shell 화면에 진입하면 성공입니다.

3. setInterval 설정

일정한 시간 간격으로 작업을 수행하기 위해서 사용하는 javascript method 입니다.

setInterval(() => testCron(), 60000)

testCron() functions을 수행하며 60000은 60초, 즉 1분마다 실행하라는 의미입니다.

profile
BACKEND 개발 기록 중. 감사합니다 😘

0개의 댓글