add scan interval time for sync command

This commit is contained in:
tickstep 2024-09-20 10:53:35 +08:00
parent fbfa313c1e
commit 05f695a882
3 changed files with 21 additions and 8 deletions

View File

@ -232,8 +232,12 @@ driveName - 网盘名称backup(备份盘)resource(资源盘)
} else { } else {
cycleMode = syncdrive.CycleInfiniteLoop 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 return nil
}, },
Flags: []cli.Flag{ Flags: []cli.Flag{
@ -297,9 +301,14 @@ driveName - 网盘名称backup(备份盘)resource(资源盘)
}, },
cli.IntFlag{ cli.IntFlag{
Name: "ldt", Name: "ldt",
Usage: "local delay time本地文件修改检测延迟间隔单位秒。如果本地文件会被频繁修改例如录制视频文件配置好该时间可以避免上传未录制好的文件", Usage: "local delay time本地文件修改检测延迟间隔单位秒。如果本地文件会被频繁修改例如录制视频文件配置好该时间可以避免上传未录制好的文件",
Value: 3, 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, 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 maxDownloadRate := config.Config.MaxDownloadRate
maxUploadRate := config.Config.MaxUploadRate maxUploadRate := config.Config.MaxUploadRate
activeUser := GetActiveUser() 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", fmt.Printf("备份配置文件:%s\n下载并发%d\n上传并发%d\n下载分片大小%s\n上传分片大小%s\n",
syncConfigFile, fileDownloadParallel, fileUploadParallel, converter.ConvertFileSize(downloadBlockSize, 2), syncConfigFile, fileDownloadParallel, fileUploadParallel, converter.ConvertFileSize(downloadBlockSize, 2),
converter.ConvertFileSize(uploadBlockSize, 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) fmt.Println("启动任务失败:", e)
return return
} }

View File

@ -50,6 +50,8 @@ type (
Priority SyncPriorityOption `json:"-"` Priority SyncPriorityOption `json:"-"`
// LastSyncTime 上一次同步时间 // LastSyncTime 上一次同步时间
LastSyncTime string `json:"lastSyncTime"` LastSyncTime string `json:"lastSyncTime"`
// ScanTimeInterval 扫描文件时间间隔,单位秒
ScanTimeInterval int64 `json:"-"`
syncDbFolderPath string syncDbFolderPath string
localFileDb LocalSyncDb localFileDb LocalSyncDb
@ -497,7 +499,7 @@ func (t *SyncTask) scanLocalFile(ctx context.Context) {
fileInfo: rootFolder, fileInfo: rootFolder,
path: t.LocalFolderPath, path: t.LocalFolderPath,
}) })
delayTimeCount = TimeSecondsOfOneMinute delayTimeCount = t.ScanTimeInterval
continue continue
} }
item := obj.(*folderItem) item := obj.(*folderItem)
@ -718,7 +720,7 @@ func (t *SyncTask) scanPanFile(ctx context.Context) {
// 无限循环模式,继续下一次扫描 // 无限循环模式,继续下一次扫描
folderQueue.Push(rootPanFile) folderQueue.Push(rootPanFile)
delayTimeCount = TimeSecondsOfOneMinute delayTimeCount = t.ScanTimeInterval
continue continue
} }
item := obj.(*aliyunpan.FileEntity) item := obj.(*aliyunpan.FileEntity)

View File

@ -116,7 +116,7 @@ func (m *SyncTaskManager) ConfigFilePath() string {
} }
// Start 启动同步进程 // 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 { if tasks != nil && len(tasks) > 0 {
m.syncDriveConfig = &SyncDriveConfig{ m.syncDriveConfig = &SyncDriveConfig{
ConfigVer: "1.0", ConfigVer: "1.0",
@ -141,6 +141,8 @@ func (m *SyncTaskManager) Start(tasks []*SyncTask, cycleMode CycleMode) (bool, e
} }
// cycle mode // cycle mode
task.CycleModeType = cycleMode task.CycleModeType = cycleMode
// scan time
task.ScanTimeInterval = scanTimeInterval
// check driveId // check driveId
if strings.ToLower(task.DriveName) == "backup" { if strings.ToLower(task.DriveName) == "backup" {