I have an asynchronous desktop that works like a Tornado script on my server - it contains a subclass of Tornado PeriodicTask that uses events from Redis. To control the queue, I configured the subclass tornado.websocket.WebSocketHandlerto the URL, and then encapsulated the client WebSocket JavaScript in the jQuery plugin ( here is the full code ).
The idea is that there can be several queues on the server, so you can use the jQuery module to configure the widget that specifically controls this queue. At the moment, the logic is dead simple - widgets simply indicate how many tasks are given in the task queue.
Here is the initialization code:
function (_options) {
options = $.extend(options, _options);
var self = this;
self.data('recently', [0,0,0,0,0,0,0,0,0]);
self.data('options', options);
self.data('sock', null);
var sock = null;
if ('endpoint' in options && options['endpoint']) {
sock = new WebSocket(options['endpoint']);
sock.onopen = function () {};
sock.onclose = function () {};
sock.onmessage = function (e) {
var d = $.parseJSON(e.data);
if (options.queuename in d) {
var qlen = d[options.queuename]
lastvalues = self.data('recently');
lastvalues.shift();
lastvalues.push(qlen);
if (lastvalues.every(function (itm) { return itm == 0; })) {
self.each(function () {
var elem = $(this);
elem.html("<b>Currently Idle</b>");
});
} else {
self.each(function () {
var elem = $(this);
elem.html("<b>" + qlen + "</b> Queued Signals");
});
}
self.data('recently', lastvalues);
}
}
}
self.data('sock', sock);
return self.each(function () {
var elem = $(this);
elem.data('sock', sock);
});
}
javascript window.setInterval() ; , , DOM.
, - , -, , , DOM_ERROR_11 , .

, - script, .
... , ( window.setInterval() whatnot)?