I have a HTTP api written in golang on the go-fiber framework that handles bookings.
type Booking struct {
Active bool `bson:"active"`
Created time.Time `bson:"created"`
StartDate time.Time `bson:"start_date"`
EndDate time.Time `bson:"end_date"`
}
When a booking is created, I want to be able to send the user a notification when that booking starts, etc. These notifications are important. I also want a timer to be set which'll automatically set the booking to inactive (active: false).
If this program were to crash, or I have to restart it due to updates, all those timers would be gone.
How should I implement a system which'll gracefully restart the API and persist those timers?
My idea:
When the program restarts, I can just query & iterate through all bookings where active: true and start those timers again. Seems obvious enough?
I'd like to know if there's any other practical solution or if there's any "best practices"?