2023-05-30 18:20:49 -04:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
|
|
|
|
package census
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/errors"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/scheduler"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/util"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// RegisterJob registers the census job with the provided scheduler.
|
2023-06-09 12:41:12 -04:00
|
|
|
func RegisterJob(ctx context.Context, s *scheduler.Scheduler, lurEnabled bool, r db.Reader, w db.Writer) error {
|
2023-05-30 18:20:49 -04:00
|
|
|
const op = "census.RegisterJob"
|
|
|
|
|
if s == nil {
|
|
|
|
|
return errors.New(ctx, errors.InvalidParameter, "nil scheduler", op, errors.WithoutEvent())
|
|
|
|
|
}
|
|
|
|
|
if util.IsNil(r) {
|
|
|
|
|
return errors.New(ctx, errors.Internal, "nil DB reader", op, errors.WithoutEvent())
|
|
|
|
|
}
|
|
|
|
|
if util.IsNil(w) {
|
|
|
|
|
return errors.New(ctx, errors.Internal, "nil DB writer", op, errors.WithoutEvent())
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-09 12:41:12 -04:00
|
|
|
censusJob, err := NewCensusJobFn(ctx, lurEnabled, r, w)
|
2023-05-30 18:20:49 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("error creating census job: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if err := s.RegisterJob(ctx, censusJob); err != nil {
|
|
|
|
|
return errors.Wrap(ctx, err, op)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|