Skip to content

Commit daeac58

Browse files
committed
setup reconciler
1 parent 9f30604 commit daeac58

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

components/usage/cmd/run.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ func run() *cobra.Command {
2727
Run: func(cmd *cobra.Command, args []string) {
2828
log.Init(ServiceName, Version, true, verbose)
2929

30-
log.Info("Hello world usage server")
31-
32-
ctrl := controller.New(controller.Config{})
33-
err := ctrl.Start()
30+
ctrl, err := controller.New("@every 1m", controller.ReconcilerFunc(controller.HelloWorldReconciler))
3431
if err != nil {
35-
log.WithError(err).Fatal("Failed to start controller.")
32+
log.WithError(err).Fatal("Failed to initialize usage controller.")
3633
}
3734

35+
ctrl.Start()
36+
defer ctrl.Stop()
37+
3838
srv, err := baseserver.New("usage")
3939
if err != nil {
4040
log.WithError(err).Fatal("Failed to initialize server.")

components/usage/pkg/controller/controller.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,19 @@ type Controller struct {
3535
}
3636

3737
func (c *Controller) Start() {
38-
log.
39-
c.scheduler.Schedule(c.schedule, cron.FuncJob(func() {
38+
log.Info("Starting usage controller.")
39+
40+
c.scheduler.Schedule(c.schedule, cron.FuncJob(func() {
41+
log.Info("Starting usage reconciliation.")
42+
4043
c.runningJobs.Add(1)
4144
defer c.runningJobs.Done()
4245

4346
err := c.reconciler.Reconcile()
4447
if err != nil {
45-
log.WithError(err).Errorf("Controller run failed.")
48+
log.WithError(err).Errorf("Reconciliation run failed.")
49+
} else {
50+
log.Info("Completed usage reconciliation run without errors.")
4651
}
4752
}))
4853

@@ -51,9 +56,11 @@ func (c *Controller) Start() {
5156

5257
// Stop terminates the Controller and awaits for all running jobs to complete.
5358
func (c *Controller) Stop() {
59+
log.Info("Stopping usage controller.")
5460
// Stop any new jobs from running
5561
c.scheduler.Stop()
5662

63+
log.Info("Awaiting existing reconciliation runs to complete..")
5764
// Wait for existing jobs to finish
5865
c.runningJobs.Wait()
5966
}

components/usage/pkg/controller/reconciler.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package controller
66

7+
import "github.com/gitpod-io/gitpod/common-go/log"
8+
79
type Reconciler interface {
810
Reconcile() error
911
}
@@ -13,3 +15,8 @@ type ReconcilerFunc func() error
1315
func (f ReconcilerFunc) Reconcile() error {
1416
return f()
1517
}
18+
19+
func HelloWorldReconciler() error {
20+
log.Info("Hello world reconciler!")
21+
return nil
22+
}

0 commit comments

Comments
 (0)