-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from appuio/feat/cleanup-broken-records
Add a command to clean up stale inflight records
- Loading branch information
Showing
6 changed files
with
160 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters