Before this change, upon the completion of a job run, the scheduler would update a job_run entry with the completed status as well as the number of objects affected by the run. Additionally, we then had a cleaner job whose scope was deleting these completed entries from job_run. This commit changes this design to drop the cleaner job the and rolls its functionality directly into the scheduler. Now, when any given job run is complete, the scheduler will automatically delete it from the job_run table itself. In addition, the completed status has been removed as a valid status as it is not set anymore. This change follows a decision that given the data in these job_run entries is already being deleted by the cleaner job, updating its state when a job completes just to have it deleted is not efficient. Additionally, no use-case for this data was surfaced.
44 lines
918 B
Go
44 lines
918 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package job
|
|
|
|
import (
|
|
"github.com/hashicorp/boundary/internal/scheduler/job/store"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// Run represents an instance of a job that is either actively running or has failed in some way.
|
|
type Run struct {
|
|
*store.JobRun
|
|
tableName string `gorm:"-"`
|
|
}
|
|
|
|
func (j *Run) clone() *Run {
|
|
cp := proto.Clone(j.JobRun)
|
|
return &Run{
|
|
JobRun: cp.(*store.JobRun),
|
|
tableName: j.tableName,
|
|
}
|
|
}
|
|
|
|
func allocRun() *Run {
|
|
return &Run{
|
|
JobRun: &store.JobRun{},
|
|
}
|
|
}
|
|
|
|
// TableName returns the table name for the job run.
|
|
func (j *Run) TableName() string {
|
|
if j.tableName != "" {
|
|
return j.tableName
|
|
}
|
|
return "job_run"
|
|
}
|
|
|
|
// SetTableName sets the table name. If the caller attempts to
|
|
// set the name to "" the name will be reset to the default name "job_run".
|
|
func (j *Run) SetTableName(n string) {
|
|
j.tableName = n
|
|
}
|