Skip to content

Commit

Permalink
Change name of the function for detecting running backups
Browse files Browse the repository at this point in the history
  • Loading branch information
AMecea committed Mar 20, 2019
1 parent 5e5f039 commit 979c69b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
16 changes: 6 additions & 10 deletions pkg/controller/mysqlbackupcron/job_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ func (j *job) Run() {
}

// check if a backup is running
if j.anyScheduledBackupRunning() {
log.Info("a scheduled backup already running, skip doing another one")
if j.scheduledBackupsRunningCount() > 0 {
log.V(1).Info("at least a backup is running",
"backups_len", j.scheduledBackupsRunningCount())
return
}

Expand All @@ -59,23 +60,18 @@ func (j *job) Run() {
}
}

func (j *job) anyScheduledBackupRunning() bool {
func (j *job) scheduledBackupsRunningCount() int {
backupsList := &api.MysqlBackupList{}
// select all backups with labels recurrent=true and and not completed of the cluster
selector := j.backupSelector()
selector.MatchingField("status.completed", "false")

if err := j.c.List(context.TODO(), selector, backupsList); err != nil {
log.Error(err, "failed getting backups", "selector", selector)
return false
return 0
}

if len(backupsList.Items) == 0 {
return false
}

log.V(1).Info("at least a backup is running", "backups", backupsList.Items)
return true
return len(backupsList.Items)
}

func (j *job) createBackup() (*api.MysqlBackup, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/mysqlbackupcron/job_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ var _ = Describe("MysqlBackupCron cron job", func() {
})

It("should detect the running backup", func() {
Eventually(j.anyScheduledBackupRunning).Should(Equal(true))
Eventually(j.scheduledBackupsRunningCount).Should(Equal(1))
})

It("should not detect any running backup", func() {
backup.Status.Completed = true
Expect(c.Update(context.TODO(), backup)).To(Succeed())

Eventually(j.anyScheduledBackupRunning).Should(Equal(false))
Eventually(j.scheduledBackupsRunningCount).Should(Equal(0))
})
})
})

0 comments on commit 979c69b

Please sign in to comment.