Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6567117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:17:53+00:00 2026-05-25T14:17:53+00:00

I have an asynchronous queue worker running as a Tornado script on my server

  • 0

I have an asynchronous queue worker running as a Tornado script on my server — it hosts a subclass of Tornado’s PeriodicTask, which consumes events from Redis. To monitor the queue, I set up a tornado.websocket.WebSocketHandler subclass on a URL, and then encapsulated the client WebSocket JavaScript in a jQuery plugin (here is the full code).

The idea is, you can have a number of queues on the server, and so you can use the jQuery module to set up a widget that specifically monitors that queue. At the moment, the logic is dead simple — the widgets merely indicate how many tasks are enqueued in their target queue.

Here’s the init code in question:

    /* init: */ 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);
    });
}

The javascript uses window.setInterval() to periodically send a message to the socket; the server replies with the status of the queue for which it was asked, and the socket’s frontend callback updates the DOM.

But the problem is: after a few minutes of this sort of polling — set off specifically by navigating between pages containing the client socket code — the sockets fail by throwing an exception with a message like DOM_ERROR_11 and a message that the socket object is no longer valid.

enter image description here

Once the page enters this error condition, I have to restart both the browser and the server websocket script to get everything to start up again.

… Is there a better way to set things up than I have (with the window.setInterval() and whatnot)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:17:54+00:00Added an answer on May 25, 2026 at 2:17 pm

    Well, it’s probably not the best idea to keep a heavy object attached to DOM

    You could alternatively have a global storage (probably a dictionary) with keys to sockets mapping, and only store the key as a DOM obj attribute

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android app that communicates with a server via asynchronous socket connection
I have a WCF 4 REST service which does some processing and then returns
I have a GUI where different parts of the information shown is extracted from
I have a basic asynchronous task that performs a web request. The thread is
I have a javascript function that enters a loop and issues an asynchronous ajax
I am trying to build a distributed task queue, and I am wondering if
G'day everyone, I have a system (the source) that needs to notify another system
I have a message inspector in my WPF/WCF 4.0 application that is working great
I am a beginner in developing iPhone applications. I was doing this sample program
I need to create a project that has a web frontend to manage synchronous

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.