Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
roseduan committed Jan 7, 2024
1 parent f31d45e commit ccf1b77
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,22 @@ func Open(options Options) (*DB, error) {
go db.watcher.sendEvent(db.watchCh)
}

// enable auto merge task
if len(options.AutoMergeCronExpr) > 0 {
db.cronScheduler = cron.New(cron.WithParser(
cron.NewParser(cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor)))
db.cronScheduler.AddFunc(options.AutoMergeCronExpr, func() {
db.cronScheduler = cron.New(
cron.WithParser(
cron.NewParser(cron.SecondOptional | cron.Minute | cron.Hour |
cron.Dom | cron.Month | cron.Dow | cron.Descriptor),
),
)
_, err = db.cronScheduler.AddFunc(options.AutoMergeCronExpr, func() {
// maybe we should deal with different errors with different logic, but a background task can't omit its error.
// after auto merge, we should close and reopen the db.
_ = db.Merge(true)
})
if err != nil {
return nil, err
}
db.cronScheduler.Start()
}

Expand Down

0 comments on commit ccf1b77

Please sign in to comment.