调试通道 API Appengine

Debugging Channel API Appengine

我正在使用 Appengine 渠道 api(带有延迟任务),但它似乎无法正常工作。

这是我的服务器代码的要点:

Class Handler(webapp2.RequestHandler):
  def get(self):
    path = jinja_environment.get_template('templates/new_console.html')
    token = channel.create_channel('some_key')
    # Deferring the task.
    deferred.defer(_task, token)
    args = {}
    args['token'] = token
    self.response.out.write(path.render(args))



def _task(token):
  FeedbackThreadModel(id='id').put()
  time.sleep(60)
  channel.send_message(token, 'done')

这是我的 javascript 客户

<html>
  <head>
    <script type="text/javascript" src="/_ah/channel/jsapi"></script>
    <script>
        channel = new goog.appengine.Channel('{{ token }}');
        socket = channel.open();
        socket.onmessage = onMessage;
        onMessage = function() {
            var xhr = new XMLHttpRequest();
            xhr.open('GET', '/secondpage');
            xhr.send();
        };
      </script>
  </head>

我希望在任务完成后向 URL: '/secondpage' 发起 GET 请求,但这并没有发生。我做错了什么?

这现在似乎奏效了。显然套接字请求 javascript 应该在 html 主体中而不是在头部。工作 javascript 看起来像这样:

<html>
  <body>
    <script type="text/javascript" src="/_ah/channel/jsapi"></script>
    <script>
        channel = new goog.appengine.Channel('{{ token }}');
        socket = channel.open();
        socket.onmessage = function() {
            var xhr = new XMLHttpRequest();
            xhr.open('GET', '/secondpage');
            xhr.send();
        };
      </script>
  </body>