Welcome to the Cumulus Support forum.

Latest Cumulus MX release 3.8.4 (build 3094) - 14 September 2020 (please see announcement regarding releases since 3.5.0)
Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014 (a patch is available for 1.9.4 build 1099 that extends the date range of the NOAA report and Snow Index drop-down menus to 2030)

Use this Wiki link to Download the Software (Cumulus MX / Cumulus 1 and other related items).

gauges.js problem with $.active

Discussion of Mark Crossley's HTML5/Javascript gauges

Moderator: mcrossley

Post Reply
User avatar
HansR
Posts: 1382
Joined: Sat 20 Oct 2012 6:53 am
Weather Station: Davis Vantage Pro 2+
Operating System: Raspbian GNU/Linux 10 (Buster)
Location: Wagenborgen (NL)
Contact:

gauges.js problem with $.active

Post 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?
https://meteo-wagenborgen.nl / Cumulus 3.6.8 (build: 3084)
Davis Vantage Pro 2+ / Raspberry Pi 3 Model B Plus Rev 1.3
Raspbian Buster / 5.4.51-v7+ armv7l (before: 4.19.118)
Mono JIT compiler version 6.10.0.104 (before: 6.8.0.123)

User avatar
mcrossley
Posts: 6933
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Buster Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: gauges.js problem with $.active

Post 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));

User avatar
HansR
Posts: 1382
Joined: Sat 20 Oct 2012 6:53 am
Weather Station: Davis Vantage Pro 2+
Operating System: Raspbian GNU/Linux 10 (Buster)
Location: Wagenborgen (NL)
Contact:

Re: gauges.js problem with $.active

Post 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)?
https://meteo-wagenborgen.nl / Cumulus 3.6.8 (build: 3084)
Davis Vantage Pro 2+ / Raspberry Pi 3 Model B Plus Rev 1.3
Raspbian Buster / 5.4.51-v7+ armv7l (before: 4.19.118)
Mono JIT compiler version 6.10.0.104 (before: 6.8.0.123)

User avatar
mcrossley
Posts: 6933
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Buster Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: gauges.js problem with $.active

Post 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.

User avatar
mcrossley
Posts: 6933
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Buster Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: gauges.js problem with $.active

Post 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.

User avatar
HansR
Posts: 1382
Joined: Sat 20 Oct 2012 6:53 am
Weather Station: Davis Vantage Pro 2+
Operating System: Raspbian GNU/Linux 10 (Buster)
Location: Wagenborgen (NL)
Contact:

Re: gauges.js problem with $.active

Post 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: ;)
https://meteo-wagenborgen.nl / Cumulus 3.6.8 (build: 3084)
Davis Vantage Pro 2+ / Raspberry Pi 3 Model B Plus Rev 1.3
Raspbian Buster / 5.4.51-v7+ armv7l (before: 4.19.118)
Mono JIT compiler version 6.10.0.104 (before: 6.8.0.123)

User avatar
beteljuice
Posts: 3010
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: gauges.js problem with $.active

Post by beteljuice »

Silly question ...

Is jqXHR.abort(); actually necessary ?
Image
......................Imagine, what you will KNOW tomorrow !

User avatar
HansR
Posts: 1382
Joined: Sat 20 Oct 2012 6:53 am
Weather Station: Davis Vantage Pro 2+
Operating System: Raspbian GNU/Linux 10 (Buster)
Location: Wagenborgen (NL)
Contact:

Re: gauges.js problem with $.active

Post 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.
https://meteo-wagenborgen.nl / Cumulus 3.6.8 (build: 3084)
Davis Vantage Pro 2+ / Raspberry Pi 3 Model B Plus Rev 1.3
Raspbian Buster / 5.4.51-v7+ armv7l (before: 4.19.118)
Mono JIT compiler version 6.10.0.104 (before: 6.8.0.123)

User avatar
mcrossley
Posts: 6933
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2
Operating System: Buster Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: gauges.js problem with $.active

Post 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.

User avatar
HansR
Posts: 1382
Joined: Sat 20 Oct 2012 6:53 am
Weather Station: Davis Vantage Pro 2+
Operating System: Raspbian GNU/Linux 10 (Buster)
Location: Wagenborgen (NL)
Contact:

Re: gauges.js problem with $.active

Post 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. ;)
https://meteo-wagenborgen.nl / Cumulus 3.6.8 (build: 3084)
Davis Vantage Pro 2+ / Raspberry Pi 3 Model B Plus Rev 1.3
Raspbian Buster / 5.4.51-v7+ armv7l (before: 4.19.118)
Mono JIT compiler version 6.10.0.104 (before: 6.8.0.123)

Post Reply