I am using the appengine api channel (with deferred tasks), but it does not seem to work.
Here's my core server code:
Class Handler(webapp2.RequestHandler):
def get(self):
path = jinja_environment.get_template('templates/new_console.html')
token = channel.create_channel('some_key')
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')
And here is my javascript client
<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>
I expect the GET request to be triggered at URL: '/ secondpage' after the task completes, but this will not happen. What am I doing wrong?
source
share