2026-04-06 15:48:37 +05:30
|
|
|
// Copyright IBM Corp. 2020, 2026
|
2023-05-30 18:20:49 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
|
|
|
|
package census
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
2026-01-14 19:58:51 +05:30
|
|
|
"io"
|
2023-05-30 18:20:49 -04:00
|
|
|
|
2026-10-12 10:33:41 -07:00
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db"
|
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/errors"
|
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/scheduler"
|
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/util"
|
2023-05-30 18:20:49 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// RegisterJob registers the census job with the provided scheduler.
|
2026-01-14 19:58:51 +05:30
|
|
|
func RegisterJob(ctx context.Context, s *scheduler.Scheduler, lurEnabled bool, r db.Reader, w db.Writer, randomReader io.Reader) 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())
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-14 19:58:51 +05:30
|
|
|
censusJob, err := NewCensusJobFn(ctx, lurEnabled, r, w, randomReader)
|
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
|
|
|
|
|
}
|