desbma / stfed

Syncthing Folder Event Daemon
GNU General Public License v3.0
20 stars 2 forks source link

Feature: able to ignore first occurence of an event after start #5

Open mailinglists35 opened 3 days ago

mailinglists35 commented 3 days ago

After some time, about an hour, the process exited with:

stfed[12083]: Error: timed out reading response (despite syncthing still running)

This in turn caused the systemd to restart the user service.

I noticed that on first start, the process considers an event even if actually it was from the last time it happened. But the process cannot know if that happened after the process started or not, correct? it just processes that was an event.

stfed[3568]: INFO [stfed] New event: FolderDownSyncDone { folder: "/home/user/Sync" }

So I'm thinking what if later I'll keep getting spurious time outs, maybe the process should ignore the even during the first seconds (or first minute, to be safe) after it established talking to syncthing.

What do you think? It would be very helpful for me anyway, since I power off with that event :)

Thanks!

mailinglists35 commented 2 days ago

hm, this seems to happen every hour. coincides with 3600 seconds from src/syncthing.rs const EVENT_STREAM_TIMEOUT: Duration = Duration::from_secs(60 * 60);

Sep 18 22:37:04 stfed[21238]: INFO  [stfed] New event: FileDownSyncDone { path: "artificii2023hd-00.03.00.082-00.03.05.458.mkv", folder: "/home/user/Sync" }
Sep 18 23:09:42 stfed[21238]: INFO  [stfed] New event: FileDownSyncDone { path: "IMG_0935.mov-00.00.37.521-00.00.43.619.mkv", folder: "/home/user/Sync" }
Sep 18 23:09:42 stfed[21238]: INFO  [stfed] New event: FolderDownSyncDone { folder: "/home/user/Sync" }
Sep 18 23:09:42 stfed[21238]: INFO  [stfed::hook] Running hook: FolderHook { folder: "/home/user/Sync", event: FolderDownSyncDone, filter: None, command: ["bash", "-c", "logger 'new videos available, restarting mpv player' && pkill -x mpv"], allow_concurrent: Some(false) } with path None and folder "/home/user/Sync"
Sep 18 23:09:42 stfed[21238]: INFO  [stfed::hook] Process exited with code Some(1)
Sep 19 00:09:42 stfed[21238]: Error: timed out reading response
Sep 19 00:09:47 stfed[28110]: WARN  [stfed::config] Unable to find config file, using default config
Sep 19 00:09:47 stfed[28110]: INFO  [stfed] New event: FolderDownSyncDone { folder: "/home/user/Sync" }
Sep 19 00:09:47 stfed[28110]: INFO  [stfed::hook] Running hook: FolderHook { folder: "/home/user/Sync", event: FolderDownSyncDone, filter: None, command: ["bash", "-c", "logger 'new videos available, restarting mpv player' && pkill -x mpv"], allow_concurrent: Some(false) } with path None and folder "/home/user/Sync"
Sep 19 00:09:48 stfed[28110]: INFO  [stfed::hook] Process exited with code Some(1)
Sep 19 01:09:47 stfed[28110]: Error: timed out reading response
Sep 19 01:09:52 stfed[7002]: WARN  [stfed::config] Unable to find config file, using default config
Sep 19 01:09:52 stfed[7002]: INFO  [stfed] New event: FolderDownSyncDone { folder: "/home/user/Sync" }
Sep 19 01:09:52 stfed[7002]: INFO  [stfed::hook] Running hook: FolderHook { folder: "/home/user/Sync", event: FolderDownSyncDone, filter: None, command: ["bash", "-c", "logger 'new videos available, restarting mpv player' && pkill -x mpv"], allow_concurrent: Some(false) } with path None and folder "/home/user/Sync"
Sep 19 01:09:53 stfed[7002]: INFO  [stfed::hook] Process exited with code Some(1)
Sep 19 02:09:52 stfed[7002]: Error: timed out reading response
Sep 19 02:09:58 stfed[18109]: WARN  [stfed::config] Unable to find config file, using default config
Sep 19 02:09:58 stfed[18109]: INFO  [stfed] New event: FolderDownSyncDone { folder: "/home/user/Sync" }
Sep 19 02:09:58 stfed[18109]: INFO  [stfed::hook] Running hook: FolderHook { folder: "/home/user/Sync", event: FolderDownSyncDone, filter: None, command: ["bash", "-c", "logger 'new videos available, restarting mpv player' && pkill -x mpv"], allow_concurrent: Some(false) } with path None and folder "/home/user/Sync"
Sep 19 02:09:58 stfed[18109]: INFO  [stfed::hook] Process exited with code Some(1)
Sep 19 03:09:58 stfed[18109]: Error: timed out reading response
Sep 19 03:10:03 stfed[29255]: WARN  [stfed::config] Unable to find config file, using default config
Sep 19 03:10:03 stfed[29255]: INFO  [stfed] New event: FolderDownSyncDone { folder: "/home/user/Sync" }
Sep 19 03:10:03 stfed[29255]: INFO  [stfed::hook] Running hook: FolderHook { folder: "/home/user/Sync", event: FolderDownSyncDone, filter: None, command: ["bash", "-c", "logger 'new videos available, restarting mpv player' && pkill -x mpv"], allow_concurrent: Some(false) } with path None and folder "/home/user/Sync"
Sep 19 03:10:03 stfed[29255]: INFO  [stfed::hook] Process exited with code Some(1)
Sep 19 04:10:03 stfed[29255]: Error: timed out reading response
Sep 19 04:10:08 stfed[8167]: WARN  [stfed::config] Unable to find config file, using default config
Sep 19 04:10:08 stfed[8167]: INFO  [stfed] New event: FolderDownSyncDone { folder: "/home/user/Sync" }
Sep 19 04:10:08 stfed[8167]: INFO  [stfed::hook] Running hook: FolderHook { folder: "/home/user/Sync", event: FolderDownSyncDone, filter: None, command: ["bash", "-c", "logger 'new videos available, restarting mpv player' && pkill -x mpv"], allow_concurrent: Some(false) } with path None and folder "/home/user/Sync"
Sep 19 04:10:09 stfed[8167]: INFO  [stfed::hook] Process exited with code Some(1)
Sep 19 05:10:08 stfed[8167]: Error: timed out reading response
Sep 19 05:10:13 stfed[19265]: WARN  [stfed::config] Unable to find config file, using default config
Sep 19 05:10:13 stfed[19265]: INFO  [stfed] New event: FolderDownSyncDone { folder: "/home/user/Sync" }
Sep 19 05:10:13 stfed[19265]: INFO  [stfed::hook] Running hook: FolderHook { folder: "/home/user/Sync", event: FolderDownSyncDone, filter: None, command: ["bash", "-c", "logger 'new videos available, restarting mpv player' && pkill -x mpv"], allow_concurrent: Some(false) } with path None and folder "/home/user/Sync"
Sep 19 05:10:14 stfed[19265]: INFO  [stfed::hook] Process exited with code Some(1)
Sep 19 06:10:13 stfed[19265]: Error: timed out reading response
Sep 19 06:10:19 stfed[30379]: WARN  [stfed::config] Unable to find config file, using default config
Sep 19 06:10:19 stfed[30379]: INFO  [stfed] New event: FolderDownSyncDone { folder: "/home/user/Sync" }
Sep 19 06:10:19 stfed[30379]: INFO  [stfed::hook] Running hook: FolderHook { folder: "/home/user/Sync", event: FolderDownSyncDone, filter: None, command: ["bash", "-c", "logger 'new videos available, restarting mpv player' && pkill -x mpv"], allow_concurrent: Some(false) } with path None and folder "/home/user/Sync"
Sep 19 06:10:19 stfed[30379]: INFO  [stfed::hook] Process exited with code Some(1)
Sep 19 07:10:19 stfed[30379]: Error: timed out reading response
Sep 19 07:10:24 stfed[9264]: WARN  [stfed::config] Unable to find config file, using default config
Sep 19 07:10:24 stfed[9264]: INFO  [stfed] New event: FolderDownSyncDone { folder: "/home/user/Sync" }
Sep 19 07:10:24 stfed[9264]: INFO  [stfed::hook] Running hook: FolderHook { folder: "/home/user/Sync", event: FolderDownSyncDone, filter: None, command: ["bash", "-c", "logger 'new videos available, restarting mpv player' && pkill -x mpv"], allow_concurrent: Some(false) } with path None and folder "/home/user/Sync"
Sep 19 07:10:24 stfed[9264]: INFO  [stfed::hook] Process exited with code Some(1)
Sep 19 08:00:02 stfed[9264]: WARN  [stfed] Syncthing server is gone, will restart main loop. ServerGone { inner: Custom { kind: InvalidInput, error: DecoderError } }
Sep 19 08:00:02 stfed[9264]: INFO  [stfed] Will reconnect in 60s

note the 60s that I changed from default of 5s

mailinglists35 commented 2 days ago

oh, I get it now. syncthing emits events from zero to infinite.

if you start stfed after syncthing has already got some events, you will receive all of them when you make the rest api query with since=0

hm. maybe you could remember the number of the highest event count returned by api, on first rest api request, do not invoke the hook, then start watching from that event+1 ?

mailinglists35 commented 2 days ago

it seems to allow asking for future ids, If <lastSeenID> is a future ID, the HTTP call blocks until such ID is reached or timeouts

mailinglists35 commented 2 days ago

so to avoid getting the alert i should start stfed exactly at the same time as syncthing (note to self!)

mailinglists35 commented 2 days ago

and I understand now the other issue, the one hour timeout, which is defined as EVENT_STREAM_TIMEOUT and passed as &timeout= to api url - I'll just increase it to my needs.

desbma commented 7 hours ago

The timeout issue should be fixed by ed8d17cb6b6c5de60390116b7b23411bfccc42c8.

so to avoid getting the alert i should start stfed exactly at the same time as syncthing (note to self!)

Yes, that is how it is intended to be used. If you use the systemd service, that should be done automatically with the PartOf relation.