Google App Engine でcronを設定する
Google App Engine for Python で cron を設定する場合のメモ。
cron.yamlを作成する
app.yamlと同じルートディレクトリにcron.yamlを設置します。
cron: - description: daily summary job url: /tasks/summary schedule: every 24 hours - description: monday morning mailout url: /mail/weekly schedule: every monday of month 09:00
cron.yamlのフォーマット
cron.yamlのscheduleには、基本的に下記のフォーマットを使用します。
("every"|ordinal) (days) "of" (monthspec) (time)
「ordinal」には「"1st", "first"」などの条件をカンマ区切りのリストを指定します。
「days」には曜日をカンマ区切りのリストで指定します(「"mon","tuesday"」など。長いフォーマット、短いフォーマットのいずれも使用できます)。
「monthspec」には月の名前をカンマ区切りのリストで指定します(「"jan","march","sep"」など)。
「time」には一日の中の時間を 24 時間表記で HH:MM の形式で指定します。
# 5分毎 every 5 minutes # 12時間毎 every 12 hours # 3月の第2、第3、月、水、木曜日の17時 2nd,third mon,wed,thu of march 17:00 # 月曜日の9時 every monday of month 09:00 # 9月、10月、11月の第1月曜日の17時 1st monday of sep,oct,nov 17:00
Googleで検索しても、上記のような細かい設定は出てくるものの、普通に毎週とか毎月の記述が見つからなくてハマりました><
# Daily: every day 00:00 # Weekly: every monday 00:00 # Monthly: 1 of month 00:00 # Yearly: 1 of jan 00:00
こんな感じで、結構、柔軟に設定できるようです。