Page 1 of 1

gauges.js problem with $.active

Posted: Mon 23 Mar 2020 12:18 pm
by HansR
I am experimenting some things which means several ajax-calls at the same time may occur.

In gauges.js there is:

Code: Select all

        getRealtime = function () {
            var url = config.realTimeURL;
            if ($.active > 0 ) {
                // kill any outstanding requests
                jqXHR.abort();
            }

which results in an abort attempt with jqXHR == null, probably because somewhere else another ajax call is outstanding which has increased $.active without the implicit meaning jqXHR has been set. Apparently this has never interfered with the normal realtime.txt but it does with my construction (simply reading files for HTML changes other than the realtime stuff)

So I changed the code in:

Code: Select all

        getRealtime = function () {
            var url = config.realTimeURL;
            if ($.active > 0 && jqXHR != null /* HAR */) {
                // kill any outstanding requests
                jqXHR.abort();
            }


When running this I get another problem:

Code: Select all

            if (!dashboard) {
                // Go do get the data!
                getRealtime();

                // start a timer to update the status time
                tickTockInterval = setInterval(
                    function () {
                        $.publish('gauges.clockTick', null);
                    },
                    1000);

Which provoques the message :
TypeError: $.publish is not a function
with different stacktraces.

Before I try to find this all, has anybody, specifically Mark, any remarks on this and an idea of where to go to solve the issue?

Re: gauges.js problem with $.active

Posted: Mon 23 Mar 2020 12:22 pm
by mcrossley
$.publish is what pushes the data to the gauges.
It is defined by Tiny Pub/Sub at the top of gauges.js

Code: Select all

/*! Tiny Pub/Sub - v0.7.0 - 2013-01-29
* https://github.com/cowboy/jquery-tiny-pubsub
* Copyright (c) 2013 "Cowboy" Ben Alman; Licensed MIT */
(function($) {
    'use strict';
    var o = $({});
    $.subscribe = function() {o.on.apply(o, arguments);};
    $.unsubscribe = function() {o.off.apply(o, arguments);};
    $.publish = function() {o.trigger.apply(o, arguments);};
}(jQuery));

Re: gauges.js problem with $.active

Posted: Mon 23 Mar 2020 12:28 pm
by HansR
OK, so any idea why I suddenly get the message it is not a function when I double check jqXHR for null?

And how do you look at the $.active issue? Should it be possible what I would like to do (other Ajax calls while timer event goes off)?

Re: gauges.js problem with $.active

Posted: Mon 23 Mar 2020 12:35 pm
by mcrossley
By adding additional ajax to the same page, then yes you are going to trip the active flag if they are running when the gauges does its refresh. I guess you could change it to use a variable flag that is set/unset when the gauge ajax starts and completes/fails.

Re: gauges.js problem with $.active

Posted: Mon 23 Mar 2020 12:40 pm
by mcrossley
The $ object is global afaik, so as long as the tiny pub/sub code has run $.publish should be there - unless you include another copy of JQuery in the containing page which overwrites the addition.

Re: gauges.js problem with $.active

Posted: Mon 23 Mar 2020 12:52 pm
by HansR
mcrossley wrote: Mon 23 Mar 2020 12:35 pm By adding additional ajax to the same page, then yes you are going to trip the active flag if they are running when the gauges does its refresh. I guess you could change it to use a variable flag that is set/unset when the gauge ajax starts and completes/fails.
I do that with the check on the jqXHR variable, which gets set when running and unset when finished. So far it's a riddle...
mcrossley wrote: Mon 23 Mar 2020 12:40 pm The $ object is global afaik, so as long as the tiny pub/sub code has run $.publish should be there - unless you include another copy of JQuery in the containing page which overwrites the addition.
I understand, but it miraculously disappears when checking jqXHR.

OK, no simple easy error on my side apparently. I'll try some other things :groan: ;)

Re: gauges.js problem with $.active

Posted: Mon 23 Mar 2020 1:12 pm
by beteljuice
Silly question ...

Is jqXHR.abort(); actually necessary ?

Re: gauges.js problem with $.active

Posted: Mon 23 Mar 2020 1:15 pm
by HansR
beteljuice wrote: Mon 23 Mar 2020 1:12 pm Silly question ...

Is jqXHR.abort(); actually necessary ?
1) Ehmm... why?
2) Not sure, maybe not. But it is there, I am not going to remove it.

Re: gauges.js problem with $.active

Posted: Mon 23 Mar 2020 1:54 pm
by mcrossley
beteljuice wrote: Mon 23 Mar 2020 1:12 pm Silly question ...

Is jqXHR.abort(); actually necessary ?
I had a issue at one time when there was a problem on the web server with hung requests piling up and consuming large amounts of memory. You'd think they'd timeout and clean themselves up, but they didn't appear to. Maybe it was an old version of JQuery and it is no longer a issue, I don't know. The abort shouldn't be a problem as it is only affecting the gauge json download.

Re: gauges.js problem with $.active

Posted: Mon 23 Mar 2020 2:44 pm
by HansR
mcrossley wrote: Mon 23 Mar 2020 1:54 pm I had a issue at one time when there was a problem on the web server with hung requests piling up and consuming large amounts of memory. You'd think they'd timeout and clean themselves up, but they didn't appear to. Maybe it was an old version of JQuery and it is no longer a issue, I don't know. The abort shouldn't be a problem as it is only affecting the gauge json download.
Ah yes, it could be some javascript issue but I think it really is something I did, so it has to be me to clean up :)

And the abort error is an issue because it stops everything and I have to reload the page. That's not what I am looking for.
mcrossley wrote: Mon 23 Mar 2020 12:40 pm The $ object is global afaik, so as long as the tiny pub/sub code has run $.publish should be there - unless you include another copy of JQuery in the containing page which overwrites the addition.
First I do other things, then look again and at least I noticed one load of jQuery too many. That improves things already.
Now going for the final fix somewhere. That may take a bit more time and other things doing.... I am getting there. ;)