2023-05-30 18:20:49 -04:00
|
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
|
|
|
|
|
|
package census
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
|
|
|
|
"github.com/hashicorp/boundary/internal/errors"
|
|
|
|
|
|
"github.com/hashicorp/boundary/internal/scheduler"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
NewCensusJobFn = newCensusJob
|
|
|
|
|
|
RunFn = runInternal
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type censusJob struct {
|
2024-02-16 16:40:44 +00:00
|
|
|
|
r db.Reader
|
|
|
|
|
|
w db.Writer
|
|
|
|
|
|
lurEnabled bool
|
2024-02-20 21:28:01 +00:00
|
|
|
|
emitEvents bool
|
2024-02-16 16:40:44 +00:00
|
|
|
|
sessionsAgent any
|
|
|
|
|
|
activeUsersAgent any
|
|
|
|
|
|
eventCtx context.Context
|
2023-05-30 18:20:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-09 12:41:12 -04:00
|
|
|
|
func newCensusJob(ctx context.Context, lurEnabled bool, r db.Reader, w db.Writer) (*censusJob, error) {
|
2023-05-30 18:20:49 -04:00
|
|
|
|
const op = "censusJob.newCensusJob"
|
|
|
|
|
|
switch {
|
|
|
|
|
|
case r == nil:
|
|
|
|
|
|
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing db.Reader")
|
|
|
|
|
|
case w == nil:
|
|
|
|
|
|
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing db.Writer")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return &censusJob{
|
2024-02-16 16:40:44 +00:00
|
|
|
|
r: r,
|
|
|
|
|
|
w: w,
|
|
|
|
|
|
lurEnabled: lurEnabled,
|
2024-02-20 21:28:01 +00:00
|
|
|
|
emitEvents: false,
|
2024-02-16 16:40:44 +00:00
|
|
|
|
sessionsAgent: nil,
|
|
|
|
|
|
activeUsersAgent: nil,
|
|
|
|
|
|
eventCtx: ctx,
|
2023-05-30 18:20:49 -04:00
|
|
|
|
}, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Status reports the job’s current status.
|
|
|
|
|
|
func (c *censusJob) Status() scheduler.JobStatus {
|
|
|
|
|
|
return scheduler.JobStatus{}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Run performs the required work depending on the implementation.
|
|
|
|
|
|
// The context is used to notify the job that it should exit early.
|
2024-09-20 12:14:29 -04:00
|
|
|
|
func (c *censusJob) Run(ctx context.Context, _ time.Duration) error {
|
2023-05-30 18:20:49 -04:00
|
|
|
|
err := RunFn(ctx, c)
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func runInternal(ctx context.Context, c *censusJob) error {
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NextRunIn returns the duration until the next job run should be scheduled.
|
2023-07-05 15:33:18 -04:00
|
|
|
|
// Census will run every hour to ensure any interrupted jobs will be re-attempted
|
2023-05-30 18:20:49 -04:00
|
|
|
|
func (c *censusJob) NextRunIn(_ context.Context) (time.Duration, error) {
|
2023-07-05 15:33:18 -04:00
|
|
|
|
return time.Hour, nil
|
2023-05-30 18:20:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Name is the unique name of the job.
|
|
|
|
|
|
func (c *censusJob) Name() string {
|
|
|
|
|
|
return "job_run_census"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Description is the human-readable description of the job.
|
|
|
|
|
|
func (c *censusJob) Description() string {
|
|
|
|
|
|
return "Gathers and exports session usage metrics"
|
|
|
|
|
|
}
|