Skip to content

Commit

Permalink
add scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
Elbehery committed Jul 9, 2024
1 parent 4794421 commit fa0a0d5
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions pkg/cmd/backuprestore/backupnoconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import (
"context"
"errors"
"fmt"
backupv1alpha1 "github.com/openshift/api/config/v1alpha1"
configversionedclientv1alpha1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1alpha1"
gcron "github.com/go-co-op/gocron/v2"
"io"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/clientcmd"
"os/exec"
"slices"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
backupv1alpha1 "github.com/openshift/api/config/v1alpha1"
configversionedclientv1alpha1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1alpha1"

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

type backupNoConfig struct {
Expand Down Expand Up @@ -66,6 +68,7 @@ func (b *backupNoConfig) Run() error {
return err
}

go b.scheduleBackup()
return nil
}

Expand Down Expand Up @@ -129,6 +132,24 @@ func (b *backupNoConfig) backup() error {
return nil
}

func (b *backupNoConfig) scheduleBackup() error {
s, _ := gcron.NewScheduler()
defer func() { _ = s.Shutdown() }()

if _, err := s.NewJob(
gcron.CronJob(
b.schedule,
false,
),
gcron.NewTask(b.backup()),
); err != nil {
return err
}

s.Start()
return nil
}

func (b *backupNoConfig) copySnapshot() error {
if !b.snapshotExist {
klog.Errorf("run: backup failed: [%v]", errors.New("no snapshot file exists"))
Expand Down

0 comments on commit fa0a0d5

Please sign in to comment.