Using the Timer in Anvil

Hi,

There’s not a lot of documentation yet on the Timer Component, but I was thinking of a good use case for it in my jobs app.

image

If a user adds a new job listing and wants it to be a featured listing, they check a box when filling out a form. (“Featured” is a field True/False field in a data table.)

image

However, I want that new job listing to be featured for one just week.

Could the Timer be used to automatically uncheck the ‘featured’ checkbox after one week? How do you use it aside from just setting its interval?

Thanks -Ian

It’s not really designed for long term events like that. Remember the timer is browser based and will only be active whilst the user’s browser is running your app (and they are on the page that contains the timer).

What you could do is, when displaying the featured jobs, have a search condition that only fetches them if their creation date is under a week old. There’s no need to necessarily set the field to False as long as you have a start date saved.

If you fancy doing some reading and playing :slight_smile:
You can’t yet set up server side timed jobs in Anvil (to run a daily job to unset the required field). If you wanted to get fancy you could, if you have a server somewhere else, set a “cron” job to fire once a day and call an Anvil API endpoint. This would be a function that would search for all jobs older than a week and set the job_featured field to False.

But to be honest, just excluding it from the search results is fine.

good to know re: the Timer, and great perspective as always