quickstart

package
v1.0.0-beta.228 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "quickstart",
	Short: "Quickstart operations",
	Long:  "Helpers for docker-compose based quickstart setup. Should not be used in production systems.",
}
View Source
var Cron = &cobra.Command{
	Use:   "cron",
	Short: "Schedule the required cron jobs in the background.",
	RunE: func(cmd *cobra.Command, args []string) error {
		s, err := gocron.NewScheduler(
			gocron.WithLogger(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
				Level: slog.LevelInfo,
			}))),
		)
		if err != nil {
			return err
		}

		namespaces := []string{"default"}
		batchSize := 10

		_, err = s.NewJob(
			gocron.DurationJob(time.Hour),
			gocron.NewTask(func() {
				slog.Info("Syncing subscriptions")

				err := internal.App.BillingSubscriptionReconciler.All(cmd.Context(), reconciler.ReconcilerAllInput{
					ReconcilerListSubscriptionsInput: reconciler.ReconcilerListSubscriptionsInput{
						Namespaces: namespaces,
						Lookback:   time.Hour,
					},
					Force: false,
				})
				if err != nil {
					slog.Error("Error syncing subscriptions", "error", err)
				}
			}),
		)
		if err != nil {
			return err
		}

		_, err = s.NewJob(
			gocron.DurationJob(time.Minute),
			gocron.NewTask(func() {
				slog.Info("Collecting invoices")

				err := internal.App.BillingCollector.All(cmd.Context(), namespaces, nil, batchSize)
				if err != nil {
					slog.Error("Error collecting invoices", "error", err)
				}
			}),
		)
		if err != nil {
			return err
		}

		_, err = s.NewJob(
			gocron.DurationJob(time.Minute),
			gocron.NewTask(func() {
				slog.Info("Advancing invoices")

				err := internal.App.BillingAutoAdvancer.All(cmd.Context(), namespaces, batchSize)
				if err != nil {
					slog.Error("Error advancing invoices", "error", err)
				}
			}),
		)
		if err != nil {
			return err
		}

		if internal.App.ChargesAutoAdvancer != nil {
			_, err = s.NewJob(
				gocron.DurationJob(time.Minute),
				gocron.NewTask(func() {
					slog.Info("Advancing charges")

					err := internal.App.ChargesAutoAdvancer.All(cmd.Context(), namespaces)
					if err != nil {
						slog.Error("Error advancing charges", "error", err)
					}
				}),
			)
			if err != nil {
				return err
			}
		}

		s.Start()

		<-cmd.Context().Done()
		if err := s.Shutdown(); err != nil {
			return err
		}

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL