Do something every X seconds even if nobody is loaded on the page

Hello everyone,

I’m asking the question here because I could’t find any existing answers on the forum.

I have an X price and I want it to drop every 30 seconds by an amount of Y when I click on a Start button.

The problem with the “Do every X secondes” function is that it only runs if I stay on the page. I would like to be able to leave the page and when I come back later (or another user), the price continued to drop.

Thank you for your answers :slight_smile:

Martin

Is it important that you make the change in the database every 30 seconds?

If not, you could save a timestamp at the moment you click Start, and then calculate the price at the moment of loading the page instead (2x Y x (minutes since timestamp)). You will have to update the current date/time every 30 seconds, as it doesn’t automatically update.

That’s easier on the database too, as everything happens client-side.

Thanks for your advice. It works for having the good price if somebody reload the page, but if somebody stay in the page more than 30 secondes, it will not show the current price…

It would be perfect to have a recurring event every 30 seconds, but it seems risky for Bubble

Thanks for your advice. It works for having the good price if somebody reload the page, but if somebody stay in the page more than 30 secondes, it will not show the current price…

Yes, that’s what I mentioned briefly in my post, but maybe too briefly if you haven’t worked with these parts of Bubble before. Whenever you use current date/time in Bubble, it fetches a “snapshot” of the current time. This value doesn’t update automatically, however, only every time you call it.

So what you can do is to save the current datetime to a state instead, and then use a Do Every X Seconds workflow to update that state with the current time. That way, it will always calculate the correct price, without touching the database.

2 Likes

Yes! It’s perfectly worked with the date save as a state! Thank you very much :):smiley:

1 Like

Awesome :metal: