★★★★★
#데이터·Firebase·보안 · claude-code
Scheduled Function (Cron)
매일 정해진 시간에 자동 함수 실행.
#scheduled-function#pubsub#cron
변수 2개 — 여기 채우면 아래 프롬프트에 바로 들어가요
매일 정해진 시간에 자동 함수 실행.
시나리오:
- 매일 자정 → 일일 통계 계산
- 매주 월요일 → 주간 보고서
- 매월 1일 → 구독 갱신 확인
구현 (Node.js):
```typescript
// 매일 오전 8시(KST) = 23:00 UTC
exports.dailyReport = functions.pubsub
.schedule('0 23 * * *')
.timeZone('Asia/Seoul')
.onRun(async (context) => {
const today = new Date().toISOString().split('T')[0];
const snap = await db.collection('prayers')
.where('createdAt', '>=', new Date(today))
.get();
await db.collection('dailyReports').doc(today).set({
date: today,
totalPrayers: snap.size,
timestamp: new Date(),
});
});
// 매월 1일 01:00 UTC
exports.monthlyCheck = functions.pubsub
.schedule('0 1 1 * *')
.timeZone('Asia/Seoul')
.onRun(async (context) => {
// 구독 만료 확인 등
});
```
Cron 표현식 (분 시 일 월 요일):
- `0 8 * * *` = 매일 오전 8시
- `0 0 * * 1` = 매주 월요일 자정
- `0 0 1 * *` = 매월 1일 자정
참고: https://crontab.guru
{{SCHEDULE_TYPE}} {{TIME}}에 함수 실행할까?
쓰는 법 — 위 칸에 본인 값을 채우면 아래 프롬프트에 바로 반영돼요. 복사 버튼을 누르면 채워진 그대로 클립보드에 담기니까, claude-code(또는 본인이 쓰는 AI)에 붙여넣기만 하면 됩니다. 변수가 없으면 그냥 복사해서 쓰세요.

