github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/btpmanager/credentials/job.go (about) 1 package btpmgrcreds 2 3 import ( 4 "time" 5 6 "github.com/go-co-op/gocron" 7 "github.com/sirupsen/logrus" 8 ) 9 10 type Job struct { 11 btpOperatorManager *Manager 12 logs *logrus.Logger 13 } 14 15 func NewJob(manager *Manager, logs *logrus.Logger) *Job { 16 return &Job{ 17 btpOperatorManager: manager, 18 logs: logs, 19 } 20 } 21 22 func (s *Job) Start(autoReconcileInterval int, jobReconciliationDelay time.Duration) { 23 scheduler := gocron.NewScheduler(time.UTC) 24 _, schedulerErr := scheduler.Every(autoReconcileInterval).Minutes().Do(func() { 25 s.logs.Infof("runtime-reconciler: scheduled call starter at %s", time.Now()) 26 _, _, _, _, reconcileErr := s.btpOperatorManager.ReconcileAll(jobReconciliationDelay) 27 if reconcileErr != nil { 28 s.logs.Errorf("runtime-reconciler: scheduled call finished with error: %s", reconcileErr) 29 } else { 30 s.logs.Infof("runtime-reconciler: scheduled call finished with success at %s", time.Now().String()) 31 } 32 }) 33 34 if schedulerErr != nil { 35 s.logs.Errorf("runtime-reconciler: scheduler failure: %s", schedulerErr) 36 } 37 38 s.logs.Info("runtime-listener: start scheduler") 39 scheduler.StartAsync() 40 }