optimize sync to reduce CPU resource for docker

This commit is contained in:
tickstep 2022-06-24 22:25:40 +08:00
parent 8632c268f0
commit e8ca54cf4b
3 changed files with 18 additions and 4 deletions

View File

@ -45,6 +45,7 @@ COPY ./out/binary_files/sync_drive /home/app/config/sync_drive
HEALTHCHECK --start-period=5s --interval=10s --timeout=5s --retries=3 CMD /bin/sh /home/app/health_check.sh
# 环境变量
ENV ALIYUNPAN_DOCKER=1
ENV ALIYUNPAN_CONFIG_DIR=/home/app/config
ENV ALIYUNPAN_REFRESH_TOKEN=""

View File

@ -44,6 +44,7 @@ HEALTHCHECK --start-period=5s --interval=10s --timeout=5s --retries=3 CMD /bin/s
EXPOSE 23077
# 环境变量
ENV ALIYUNPAN_DOCKER=1
ENV ALIYUNPAN_CONFIG_DIR=/home/app/config
ENV ALIYUNPAN_AUTH_USER=admin
ENV ALIYUNPAN_AUTH_PASSWORD=admin

View File

@ -260,11 +260,23 @@ func RunSync(defaultTask *syncdrive.SyncTask, fileDownloadParallel, fileUploadPa
fmt.Println("启动任务失败:", e)
return
}
c := ""
fmt.Print("本命令不会退出如需要结束同步备份进程请输入y然后按Enter键进行停止")
for strings.ToLower(c) != "y" {
fmt.Scan(&c)
_, ok := os.LookupEnv("ALIYUNPAN_DOCKER")
if ok {
// in docker container
// 使用休眠以节省CPU资源
for {
time.Sleep(60 * time.Second)
}
} else {
// in cmd mode
c := ""
fmt.Print("本命令不会退出如需要结束同步备份进程请输入y然后按Enter键进行停止")
for strings.ToLower(c) != "y" {
fmt.Scan(&c)
}
}
fmt.Println("正在停止同步备份任务,请稍等...")
syncMgr.Stop()
}