Prompt for FolderComplete events

I’m using the rest/events endpoint to monitor what’s going on with syncthing and whether it’s fully synced, by watching for FolderComplete events. However, when my monitor starts up it doesn’t know whether we’re currently in sync or not. At the moment I’m walking the folder list and looking at /rest/db/status for each folder on startup, but this is terribly racy; in particular, if the status changes while I’m walking over that list, it’s hard to avoid my monitor getting confused. It would be really handy if there were some way to prompt syncthing to send a FolderComplete event for each folder, even if it doesn’t think it needs to; that way if we’re in sync I’ll get FolderComplete 100% events for everything and if not I’ll get FolderComplete 63% events (or whatever), and then the “detect the state on startup” code and the “detect the state when things change” code are the same thing. Is there already some way to prompt syncthing like this?

It’s not that racy if you start listening for events before you poll the /rest/db/status, is it? That’s what the GUI does at least. But no, currently you can’t trigger it other than by changing something on disk - those events are emitted when the index contents change.

Ah. This is true. I’m using “racy” in a loose sense here; if I listen for events and at the same time poll the status stuff, then I may be getting FolderComplete events at the same time as I’m receiving status, and dealing with that is hard. It’s not actually a flaw, it would just be lots easier to not have to have the initial startup code at all and just prod syncthing to say “tell me your current state, in the same way you tell me about changes” :slight_smile: No worries; I’ll do it the way I’m currently doing it…!

I could see there being a point to keeping the last event of each type/key around and being able to ask for it, though.

This ties into the idea to allow the subscriber to specify which event(s) they want, I think?

Maybesortof. But i was thinking we’d keep the last FolderCompletion for every folder, last device state event per device etc, so you could ask for /rest/events/latest and you’d get a set of events that ideally represents the current state as much as events can represent it. You can then start your subscription from the highest number seen in that set and know that you haven’t missed anything.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.