niiyan's blog

niiyanの個人ブログ。

Google App Engine の Task Queue に関するメモ

特定のキューに登録

default 以外のキューに登録する。キューの名前は前もって、queue.yaml で登録。

countdown を指定して N 秒後に実行も可能。

            # メール送信を Task Queue に登録
            
            # mai-queue という名前の Queue オブジェクトのインスタンスを作成
            mail_q = taskqueue.Queue('mail-queue')
            # Task オブジェクトのインスタンスを作成
            mail_t = taskqueue.Task(
                    countdown='60', # 60 秒後に実行
                    url='/sendmail',
                    params=dict(
                        sender='from@example.com',
                        to='to@example.com',
                        subject='mail_title',
                        body='mail_body'
                    )
                )
            # タスクを追加
            mail_q.add(mail_t)

タスクが完了したのに削除されない

調べてみたら、リダイレクトで 302 を返していたからだった。

If the execution of a particular Task fails (by returning any HTTP status code outside of the range 200-299), App Engine will attempt to retry until it succeeds. The system will back off gradually so as not to flood your application with too many requests, but it will retry failed tasks at least once a day at minimum.

http://code.google.com/intl/en/appengine/docs/python/taskqueue/overview.html

リダイレクトに関係する行を削除して、専用のテンプレートを用意したら、うまくいった。