File tree Expand file tree Collapse file tree 3 files changed +22
-8
lines changed Expand file tree Collapse file tree 3 files changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -27,14 +27,14 @@ func run() *cobra.Command {
27
27
Run : func (cmd * cobra.Command , args []string ) {
28
28
log .Init (ServiceName , Version , true , verbose )
29
29
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 ))
34
31
if err != nil {
35
- log .WithError (err ).Fatal ("Failed to start controller." )
32
+ log .WithError (err ).Fatal ("Failed to initialize usage controller." )
36
33
}
37
34
35
+ ctrl .Start ()
36
+ defer ctrl .Stop ()
37
+
38
38
srv , err := baseserver .New ("usage" )
39
39
if err != nil {
40
40
log .WithError (err ).Fatal ("Failed to initialize server." )
Original file line number Diff line number Diff line change @@ -35,14 +35,19 @@ type Controller struct {
35
35
}
36
36
37
37
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
+
40
43
c .runningJobs .Add (1 )
41
44
defer c .runningJobs .Done ()
42
45
43
46
err := c .reconciler .Reconcile ()
44
47
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." )
46
51
}
47
52
}))
48
53
@@ -51,9 +56,11 @@ func (c *Controller) Start() {
51
56
52
57
// Stop terminates the Controller and awaits for all running jobs to complete.
53
58
func (c * Controller ) Stop () {
59
+ log .Info ("Stopping usage controller." )
54
60
// Stop any new jobs from running
55
61
c .scheduler .Stop ()
56
62
63
+ log .Info ("Awaiting existing reconciliation runs to complete.." )
57
64
// Wait for existing jobs to finish
58
65
c .runningJobs .Wait ()
59
66
}
Original file line number Diff line number Diff line change 4
4
5
5
package controller
6
6
7
+ import "github.com/gitpod-io/gitpod/common-go/log"
8
+
7
9
type Reconciler interface {
8
10
Reconcile () error
9
11
}
@@ -13,3 +15,8 @@ type ReconcilerFunc func() error
13
15
func (f ReconcilerFunc ) Reconcile () error {
14
16
return f ()
15
17
}
18
+
19
+ func HelloWorldReconciler () error {
20
+ log .Info ("Hello world reconciler!" )
21
+ return nil
22
+ }
You can’t perform that action at this time.
0 commit comments