Skip to content

Commit

Permalink
默认只同步一次
Browse files Browse the repository at this point in the history
  • Loading branch information
movsb committed Nov 15, 2024
1 parent 91c1acf commit ac621e0
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions cmd/sync/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func AddCommands(parent *cobra.Command) {
ch := notify.NewOfficialChanify(chanifyToken)

full := utils.Must1(cmd.Flags().GetBool(`full`))
every := utils.Must1(cmd.Flags().GetDuration(`every`))

cred := Credential{
Author: os.Getenv(`AUTHOR`),
Expand All @@ -34,20 +35,39 @@ func AddCommands(parent *cobra.Command) {
}

gs := New(client.InitHostConfigs(), cred, ".", full)
for {

sync := func() error {
if err := gs.Sync(); err != nil {
ch.Send("同步失败", err.Error(), true)
log.Println(err)
time.Sleep(time.Minute * 15)
continue
} else {
log.Println(`同步完成。`)
ch.Send(`同步成功`, `全部完成,没有错误。`, false)
return err
}

ch.Send(`同步成功`, `全部完成,没有错误。`, false)
log.Println(`同步完成。`)
return nil
}

if every <= 0 {
if err := sync(); err != nil {
log.Fatalln(err)
}
os.Exit(0)
}

for {
for range 3 {
if err := sync(); err != nil {
log.Println(err)
time.Sleep(time.Second * 5)
continue
}
break
}
time.Sleep(time.Hour)
time.Sleep(every)
}
},
}
syncCmd.Flags().Bool(`full`, false, `初次备份是否全量扫描更新。`)
syncCmd.Flags().Duration(`every`, 0, `每隔多久同步一次。如果不设置,默认只同步一次。`)
parent.AddCommand(syncCmd)
}

0 comments on commit ac621e0

Please sign in to comment.