Implement Feature Request: Make checkinterval for monitor configurable (Issue #31) (#97)

* Implement Feature: Make checkinterval for monitor configurable
* Update monitor mode processing logic
This commit is contained in:
abraunegg 2018-08-08 05:35:18 +10:00 committed by GitHub
parent b2270ee696
commit e922a7d85e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 8 deletions

View file

@ -228,8 +228,9 @@ This file does not get created by default, and should only be created if you wan
Available options:
* `sync_dir`: directory where the files will be synced
* `skip_file`: any files or directories that match this pattern will be skipped during sync.
* `skip_file`: any files or directories that match this pattern will be skipped during sync
* `skip_symlinks`: any files or directories that are symlinked will be skipped during sync
* `monitor_interval`: time interval in seconds by which the monitor process will process local and remote changes
### sync_dir
Example: `sync_dir="~/MyDirToSync"`
@ -251,6 +252,11 @@ Example: `skip_symlinks = "true"`
Setting this to `"true"` will skip all symlinks while syncing.
### monitor_interval
Example: `monitor_interval = "300"`
The monitor interval is defined as the wait time 'between' sync's when running in monitor mode. By default without configuration, the monitor_interval is set to 45 seconds. Setting this value to 300 will run the sync process every 5 minutes.
### Selective sync
Selective sync allows you to sync only specific files and directories.
To enable selective sync create a file named `sync_list` in `~/.config/onedrive`.

2
config
View file

@ -2,3 +2,5 @@
sync_dir = "~/OneDrive"
# Skip files and directories that match this pattern
skip_file = ".*|~*"
# Wait time (seconds) between sync operations in monitor mode
monitor_interval = "45"

View file

@ -33,8 +33,12 @@ final class Config
// By default symlinks are not skipped (using string type
// instead of boolean because hashmap only stores string types)
setValue("skip_symlinks", "false");
// Configure the monitor mode loop - the number of seconds by which
// each sync operation is undertaken when idle under monitor mode
setValue("monitor_interval", "45");
// By default we will process remote deletes
setValue("no-remote-delete", "false");
setValue("no-remote-delete", "false");
if (!load(userConfigFilePath)) {
log.vlog("No config file found, using defaults");
}

View file

@ -1,6 +1,6 @@
import core.stdc.stdlib: EXIT_SUCCESS, EXIT_FAILURE;
import core.memory, core.time, core.thread;
import std.getopt, std.file, std.path, std.process, std.stdio;
import std.getopt, std.file, std.path, std.process, std.stdio, std.conv;
import config, itemdb, monitor, onedrive, selective, sync, util;
static import log;
@ -266,7 +266,8 @@ int main(string[] args)
}
if (monitor) {
log.vlog("Initializing monitor ...");
log.log("Initializing monitor ...");
log.log("OneDrive monitor interval (seconds): ", to!long(cfg.getValue("monitor_interval")));
Monitor m = new Monitor(selectiveSync);
m.onDirCreated = delegate(string path) {
log.vlog("[M] Directory created: ", path);
@ -302,13 +303,12 @@ int main(string[] args)
};
if (!downloadOnly) m.init(cfg, verbose);
// monitor loop
immutable auto checkInterval = dur!"seconds"(45);
immutable auto checkInterval = dur!"seconds"(to!long(cfg.getValue("monitor_interval")));
auto lastCheckTime = MonoTime.currTime();
while (true) {
if (!downloadOnly) m.update(online);
auto currTime = MonoTime.currTime();
if (currTime - lastCheckTime > checkInterval) {
lastCheckTime = currTime;
online = testNetwork();
if (online) {
performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly);
@ -317,19 +317,19 @@ int main(string[] args)
m.update(false);
}
}
// performSync complete, set lastCheckTime to current time
lastCheckTime = MonoTime.currTime();
GC.collect();
} else {
Thread.sleep(dur!"msecs"(100));
}
}
}
}
// workaround for segfault in std.net.curl.Curl.shutdown() on exit
onedrive.http.shutdown();
return EXIT_SUCCESS;
}
// try to synchronize the folder three times