Is there a way to persist the eventID's

I was trying to track eventId’s from syncthing and store it my application, but whenever the sychthing at the remote side restarts it starts from 0 again, for me then I dont know when did the remote got restarted and the application still waiting to get the new events after the previous eventId using since parameter. Is there a way I can get the latest eventId based on timestamp or the eventId’s shouldnt reset on synchthing restart.

It’s intended that they reset on restart. What you do is you check for the latest event ID when you get an HTTP error, with ?since=0&limit=1, and then you are back in sync.

Thanks Jakob, however I was planning to implement a logic like, I will be storing the latest event generated timestamp in my application and I have a poller which polls sychthing every 5 secs with params since=0&limit=100, and always get the last updated timestamp from the 100 records and compare it with the timestamp stored in my application to check for new disk events. So instead of relying on the id’s I m planning to use the event generated timestamp with the disk events. Do you see any pitfalls with this approach will I miss any events due to this approach. Please let me know your suggestion.

Well primary pitfall would be that you’ll miss events if there are more than 100 in five seconds, plus a bunch of unnecessary work, but you do you.

but if I call ?since=0&limit=1, then i will get the latest eventID right, how can i confirm that I havent processed any events before that, also I dont want to reprocess the events. One of the problem i faced is that, i have persisted the ID value in my db and always used since from that ID without limit. After the synchthing got restarted the app didnt get any events because the since param id was too high, so after 60 secs it got timedout and retry continues, and all those events I missed.

thinking about implementing like below

always poll since=0&limit=1

if eventID > the eventId stored in the app then the difference of the eventId’s needs to be processed by polling the synchthing with since param from the app db without the limit.

if eventID < the eventId stored in the app then the app stored eventID will reset to 0 and poll the syncthing disk events with 0, then store the last eventid to the db again.

I hope this way I dont have to reprocess the events and wont miss any events.

Ask for events since the last event ID you saw. You’ll get new events when they happen, or you’ll get an http error if Syncthing is restarting or crashed or whatever. When you see an error, use since=0, limit=1 to get the latest event ID and get in sync.

Understood Jakob, but my app can sometimes crash or sometimes the syncthing restart can be missed during its polling interval. The events are too important to get missed. So i need to have something to reply the events when the app was offline or to track the sycnthing restarts.

If you continuously listen to events you will not miss a restart during the polling interval, because there is essentially no polling interval. If your app shuts down and comes back up you do the same, check for the last event id. You will have missed events when you were down but that’s life.