I have a "JS Code" query that uses setTimeout to regularly poll one of our REST APIs so I can display semi-live state that our users need to see in our retool app. Right now I have a button that I press to start this polling mechanism, but I want to start it as soon as the retool app is loaded automatically.
The JS Code resource says my only option is to "Run query only when manually triggered", is there a place in retool where I can .trigger my query at startup?
My timeout polling code looks roughly like this (where getServerState is a RESTQuery query)
const POLL_TIMEOUT = 20 * 1000;
const doUpdate = () => {
getServerState.trigger({ onSuccess: (data) => {
const serverTime = data.serverTime;
console.log("server time = " + serverTime);
// queue up another call
setTimeout(doUpdate, POLL_TIMEOUT);
}})};
doUpdate();