LoginSignup
1
2

More than 3 years have passed since last update.

Google cloud scheduler で Functionsを定期実行する

Posted at

Google cloud scheduler で Functionsを定期実行する

はじめに

最初にSchedulerに実行させる Functionsを作成
※ 定期実行させるFunctionsの作成、デプロイはこちらの投稿を参照

ポイント
1. Functionsは以下コマンドでデプロイを行うとPub/Subトピックが自動的に作成される
2. Pub/Subを実行すると対象のFunctionsが実行される
3. Schedulerから指定した時間でPub/Subを実行しFunctionsを実行する
ポイントは--trigger-topic でこれを指定するとPub/Subで実行するFunctionsが作成される

gcloud functions deploy favorite --timeout=300 --entry-point=favorite --source=./functions/favorite --runtime python37 --trigger-topic favorite_action --allow-unauthenticated

下記は私が作ったFunctions
screencapture-console-cloud-google-functions-list-2021-01-25-00_29_17.png
Pub/Subも作られる
screencapture-console-cloud-google-cloudpubsub-topic-list-2021-01-25-00_28_58.png

スケジューラー設定

頻度はcrontabの設定と同じ
ターゲットはPub/Sub、HTTPが指定できる
今回はPub/Sub
screencapture-console-cloud-google-cloudscheduler-jobs-edit-us-central1-twitter-function-favorite-2021-01-25-00_22_57.png

トピックに対象のPub/Subを指定する
このSchedulerの場合、毎日10〜22時ちょうどにFunctionsが実行される
screencapture-console-cloud-google-cloudscheduler-jobs-edit-us-central1-twitter-function-favorite-2021-01-25-00_32_08.png

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2