Add heartbeat frequency setting

This commit is contained in:
R. Miles McCain
2020-04-24 13:22:22 -04:00
parent 9881dedac0
commit 3f7aaa8f0d
5 changed files with 30 additions and 4 deletions

View File

@@ -23,6 +23,6 @@ window.onload = function () {
);
} catch {}
}
setInterval(sendUpdate, 5000);
setInterval(sendUpdate, Number("{{heartbeat_frequency}}"));
sendUpdate();
};

View File

@@ -82,10 +82,15 @@ class ScriptView(View):
},
)
)
heartbeat_frequency = settings.SCRIPT_HEARTBEAT_FREQUENCY
return render(
self.request,
"analytics/scripts/page.js",
context={"endpoint": endpoint, "protocol": protocol},
context={
"endpoint": endpoint,
"protocol": protocol,
"heartbeat_frequency": heartbeat_frequency,
},
content_type="application/javascript",
)

View File

@@ -256,3 +256,7 @@ ONLY_SUPERUSERS_CREATE = os.getenv("ONLY_SUPERUSERS_CREATE", "True") == "True"
# Should the script use HTTPS to send the POST requests? The hostname is from
# the django SITE default. (Edit it using the admin panel.)
SCRIPT_USE_HTTPS = os.getenv("SCRIPT_USE_HTTPS", "True") == "True"
# How frequently should the tracking script "phone home" with a heartbeat, in
# milliseconds?
SCRIPT_HEARTBEAT_FREQUENCY = int(os.getenv("SCRIPT_HEARTBEAT_FREQUENCY", "5000"))