Access the Countdown value of "Run this query periodically" and use elsewhere

Is it possible to feed the countdown value of "Run this query periodically / period interval" to another component? I want to show a visual indication countdown to the user of when the query will run again.

Hey @rcanpolat!

Retool has a timer that you might be able to use for this. Queries don't have a property of the current countdown value but they do have a .timestamp property, of the last time the query was run, and a .queryRefreshTime property, that matches the "Period interval" field. Timer components also let you display time elapsed since a given moment so you can do something like:

{{moment(query1.timestamp).add(query1.queryRefreshTime, 'milliseconds')}}

to get the time until the query is run next! We can then access that raw value in timer.elapsedTimeMs. This behaves a little oddly since query1.timestamp doesn't update until after the query has run, meaning it'll go a bit past zero, but you can account for that using something like Math.min in a text component. Here's an example of what the result could look like!

2 Likes

Interesting solution, I'll work with that, thank you

Is it possible to reference from console.log() ?

I'm having an issue where i can't hide "timer1".

If i set it to hidden (or put it inside a container and set that to hidden) then the seconds don't output to "text5"

My workaround for this is to hide it in the CSS with the below. It keeps the countdown running in "text5"

div._retool-container-timer1 {
  display: none;
}

Ah! Thanks for surfacing that behavior, it's something others have expressed interest in changing and I can let you know here when it does. In the meantime, you can also try turning on "Maintain space when hidden" as a workaround, though yours looks great and I can see it being preferable :slightly_smiling_face:

And you should be able to reference both timer1.elapsedTimeMs and text1.value in your console log. If you want to make the value more readily accessible as a number you might consider using a standalone transformer!

I found another anomaly in this. I'm now using a "Query JSON with SQL" query and it doesn't produce a timestamp (when I run it by clicking run or automatically when its set to run periodically every 60,000ms)

In the "state" area on the left side of the screen for the "Query JSON with SQL" query, under timestamp it just shows "0"

So what's happening here? Is my "Query JSON with SQL" running periodically or is it not reporting back the timestamp only?

This is actually a known bug, thanks for surfacing it again! Will bump and can let you know here when it has been fixed :slightly_smiling_face: