In fact, setInterval does not work getMessages at all (not even once). setInterval expects a reference to the function, but you immediately execute the getMessages function and pass its return value to setInterval (which is undefined ). This is what parens do after getMessage .
Pass the link to setInterval as follows:
setInterval(getMessages, queryInterval);
If this is the only place that getMessages used, you can also write it like this:
setInterval(function() { console.log("tick"); }, queryInterval);
source share