-
Notifications
You must be signed in to change notification settings - Fork 1
/
cleanup.go
41 lines (33 loc) · 1.12 KB
/
cleanup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"os"
"time"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"github.com/appuio/control-api/apiserver/billing/odoostorage/odoo/odoo8"
)
// APICommand creates a new command allowing to start the API server
func CleanupCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "cleanup",
}
odooUrl := cmd.Flags().String("billing-entity-odoo8-url", "http://localhost:8069", "URL of the Odoo instance to use for billing entities")
debugTransport := cmd.Flags().Bool("billing-entity-odoo8-debug-transport", false, "Enable debug logging for the Odoo transport")
minAge := cmd.Flags().Duration("billing-entity-odoo8-cleanup-after", time.Hour, "Clean up only records older than this")
cmd.Run = func(cmd *cobra.Command, args []string) {
ctx := ctrl.SetupSignalHandler()
l := klog.FromContext(ctx)
scrubber := odoo8.NewFailedRecordScrubber(
*odooUrl,
*debugTransport,
)
err := scrubber.CleanupIncompleteRecords(ctx, *minAge)
if err != nil {
l.Error(err, "Unable to clean up incomplete records")
os.Exit(1)
}
l.Info("Cleanup complete!")
}
return cmd
}