firebase cloudFunctionsを定期実行するまで
プロジェクトを作成
firebaseから「コンソールへ移動」をクリックし、プロジェクトを作成する
必要なものをinstall
・'npm install -g firebase-tools':cliでfirebaseコマンドを使えるようにする
・'firebase login':cliからgoogleアカウントを使ってfirebaseへログインする
・'firebase init':firebaseのためのディレクトリやファイルを作成する
※ここで、使う機能や設定に関して質問されるので自分の希望通りに選択する
apiKey
firebaseのapikey:firebaseの歯車マークを押して「プロジェクトの設定」→「サービスアカウント」で秘密鍵を生成する
※これをfunction/indexに読み込ませる。
※cloudfunctionsを使うだけの場合は不要。
デプロイ
'firebase deploy':デプロイコマンド
※functionsだけをデプロイしたい時には、'firebase deploy --only functions'
lib/src/index.js:このファイルが最終的に読まれている
// function/src/index.ts
import * as functions from 'firebase-functions';
import { hoge } from './hoge';
export const scheduledFunctionCrontab = functions
.region('asia-northeast1')
.pubsub.schedule('* * * * *')
.timeZone('Asia/Tokyo')
.onRun((context) => {
hoge();
});