わらってごまかす

ごまかしちゃだめ

Google App Engineでcronの設定をする

Google App Engine で自動実行をさせたいときはcron.yamlを編集します。
アプリケーションを作るとき、デフォルトではこのファイルは無いので自分で作ることになる。

例えばこんな感じ

cron:
- description: tweet_post
  url: /tweet
  schedule: every 2 hours from 8:00 to 24:00
  timezone: Asia/Tokyo

description 説明書き。
url cronがアクセスするurl。ここにアクセスするとコードが実行される。
schedule 実行する間隔を指定する。書式が決まっている。
timezone これを指定しておくと、scheduleを日本時間で記述できる。

scheduleの記述の書式の例

(引用:GAE公式Scheduled Tasks With Cron for Python - Python — Google Cloud Platform

every 12 hours
every 5 minutes from 10:00 to 14:00
2nd,third mon,wed,thu of march 17:00
every monday 09:00
1st monday of sep,oct,nov 17:00
every day 00:00

普通のサーバーでcrontabを編集する際はvimemacsなどで書くことになり、慣れていない人にとってはつらいものがある。しかし、これならば簡単かつぱっと見でもも分かりやすい。さすがGoogle