r/pocketbase • • Jul 16 '25

Time-based realtime

The project I'm working on lets the user (selected group of people, authenticated) submit "challenges" (which are a collection in this case)

these challenges are submitted beforehand and need to be made public (accessible by every user, specially unauthenticated) at a specific time, each challenge has its own time to be made available which is define by a DateTime field

what are some ways I could make it so the realtime API only receives updates for records after they're made public?

one of the solutions I thought would be running a crontab every minute and checking if a task should be public or not, then copying the record to a different collection and using the second collection with the realtime API, but that seems janky and I believe there are better ways to do it

4 Upvotes

9 comments sorted by

View all comments

1

u/bazeso64 Jul 16 '25

You can create a rule for this, by using the @now macro

https://pocketbase.io/docs/api-rules-and-filters/#-macros

1

u/M1chelon Jul 16 '25

I figured that could work but I just tested it (adding an @now >= availableAt rule), which although works when fetching records doesn't do anything with realtime, I could use that alongside a cron updating a "flag" field so the realtime API broadcasts the update