From 05f695a8825961da1a07d616f580b51ca1269064 Mon Sep 17 00:00:00 2001 From: tickstep Date: Fri, 20 Sep 2024 10:53:35 +0800 Subject: [PATCH] add scan interval time for sync command --- internal/command/sync.go | 19 ++++++++++++++----- internal/syncdrive/sync_task.go | 6 ++++-- internal/syncdrive/sync_task_mgr.go | 4 +++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/internal/command/sync.go b/internal/command/sync.go index 06dc187..f8a6782 100644 --- a/internal/command/sync.go +++ b/internal/command/sync.go @@ -232,8 +232,12 @@ driveName - 网盘名称,backup(备份盘),resource(资源盘) } else { cycleMode = syncdrive.CycleInfiniteLoop } - RunSync(task, cycleMode, dp, up, downloadBlockSize, uploadBlockSize, syncOpt, c.Int("ldt")) - + scanIntervalTime := int64(c.Int("sit") * 60) + if scanIntervalTime == 0 { + // 默认1分钟 + scanIntervalTime = 60 + } + RunSync(task, cycleMode, dp, up, downloadBlockSize, uploadBlockSize, syncOpt, c.Int("ldt"), scanIntervalTime) return nil }, Flags: []cli.Flag{ @@ -297,9 +301,14 @@ driveName - 网盘名称,backup(备份盘),resource(资源盘) }, cli.IntFlag{ Name: "ldt", - Usage: "local delay time,本地文件修改检测延迟间隔,单位秒。如果本地文件会被频繁修改,例如录制视频文件,配置好该时间可以避免上传未录制好的文件", + Usage: "local delay time,本地文件修改检测延迟间隔,单位秒。如果本地文件会被频繁修改,例如录制视频文件,配置好该时间可以避免上传未录制好的文件。", Value: 3, }, + cli.IntFlag{ + Name: "sit", + Usage: "scan interval time,扫描文件间隔时间,单位:分钟。", + Value: 1, + }, }, }, }, @@ -307,7 +316,7 @@ driveName - 网盘名称,backup(备份盘),resource(资源盘) } func RunSync(defaultTask *syncdrive.SyncTask, cycleMode syncdrive.CycleMode, fileDownloadParallel, fileUploadParallel int, downloadBlockSize, uploadBlockSize int64, - flag syncdrive.SyncPriorityOption, localDelayTime int) { + flag syncdrive.SyncPriorityOption, localDelayTime int, scanTimeInterval int64) { maxDownloadRate := config.Config.MaxDownloadRate maxUploadRate := config.Config.MaxUploadRate activeUser := GetActiveUser() @@ -369,7 +378,7 @@ func RunSync(defaultTask *syncdrive.SyncTask, cycleMode syncdrive.CycleMode, fil fmt.Printf("备份配置文件:%s\n下载并发:%d\n上传并发:%d\n下载分片大小:%s\n上传分片大小:%s\n", syncConfigFile, fileDownloadParallel, fileUploadParallel, converter.ConvertFileSize(downloadBlockSize, 2), converter.ConvertFileSize(uploadBlockSize, 2)) - if _, e := syncMgr.Start(tasks, cycleMode); e != nil { + if _, e := syncMgr.Start(tasks, cycleMode, scanTimeInterval); e != nil { fmt.Println("启动任务失败:", e) return } diff --git a/internal/syncdrive/sync_task.go b/internal/syncdrive/sync_task.go index f059d61..97b693f 100644 --- a/internal/syncdrive/sync_task.go +++ b/internal/syncdrive/sync_task.go @@ -50,6 +50,8 @@ type ( Priority SyncPriorityOption `json:"-"` // LastSyncTime 上一次同步时间 LastSyncTime string `json:"lastSyncTime"` + // ScanTimeInterval 扫描文件时间间隔,单位秒 + ScanTimeInterval int64 `json:"-"` syncDbFolderPath string localFileDb LocalSyncDb @@ -497,7 +499,7 @@ func (t *SyncTask) scanLocalFile(ctx context.Context) { fileInfo: rootFolder, path: t.LocalFolderPath, }) - delayTimeCount = TimeSecondsOfOneMinute + delayTimeCount = t.ScanTimeInterval continue } item := obj.(*folderItem) @@ -718,7 +720,7 @@ func (t *SyncTask) scanPanFile(ctx context.Context) { // 无限循环模式,继续下一次扫描 folderQueue.Push(rootPanFile) - delayTimeCount = TimeSecondsOfOneMinute + delayTimeCount = t.ScanTimeInterval continue } item := obj.(*aliyunpan.FileEntity) diff --git a/internal/syncdrive/sync_task_mgr.go b/internal/syncdrive/sync_task_mgr.go index 7d5058a..37f244f 100644 --- a/internal/syncdrive/sync_task_mgr.go +++ b/internal/syncdrive/sync_task_mgr.go @@ -116,7 +116,7 @@ func (m *SyncTaskManager) ConfigFilePath() string { } // Start 启动同步进程 -func (m *SyncTaskManager) Start(tasks []*SyncTask, cycleMode CycleMode) (bool, error) { +func (m *SyncTaskManager) Start(tasks []*SyncTask, cycleMode CycleMode, scanTimeInterval int64) (bool, error) { if tasks != nil && len(tasks) > 0 { m.syncDriveConfig = &SyncDriveConfig{ ConfigVer: "1.0", @@ -141,6 +141,8 @@ func (m *SyncTaskManager) Start(tasks []*SyncTask, cycleMode CycleMode) (bool, e } // cycle mode task.CycleModeType = cycleMode + // scan time + task.ScanTimeInterval = scanTimeInterval // check driveId if strings.ToLower(task.DriveName) == "backup" {