Files
threshold/internal/scheduler/job.go
T
Jim 591ec476e7 refactor: Update internal/db and oplog to use go-dbw package for database operations. (#1785)
* chore: Add new dbw dependency

* refactor: Convert to use dbw.DB

* refactor (db): Change GetTicket(...) signature

* feature (db tests): Added TestDeleteWhere(...)
Adding this allows us to eliminate a leak of the gorm library

* refactor: Add ctx to ScanRows(...) signature
This is required to refactor all the deprecated errors pkg calls.
This refactor required adding a context to quite a few call chains
and in particular the job scheduler bits

* feature (db/tests): Add support for test opt: WithTestLogLevel(...)
This test only option allows callers to specify a log level for the
underlying db package (where supported/applicable) when calling
TestSetup(...)

* refactor (db): Simplify Db type
Only store the underlying *DB and create the *RW on demand when
needed.

* refactor (oplog): Port to using dbw pkg for db operations

* refactor (db): Remove gormDB(...) func

* tests (db): Add unit tests for TestDeleteWhere(...)

* chore: make fmt changes to formatting
2022-01-05 14:38:38 -05:00

55 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package scheduler
import (
"context"
"time"
"github.com/hashicorp/boundary/internal/errors"
)
// Job defines an interface for jobs that can be invoked by the scheduler.
type Job interface {
// Status reports the job’s current status. The status is periodically persisted by
// the scheduler when a job is running, and will be used to verify a job is making progress.
Status() JobStatus
// Run performs the required work depending on the implementation.
// The context is used to notify the job that it should exit early.
Run(ctx context.Context) error
// NextRunIn returns the duration until the next job run should be scheduled. This
// method is invoked after a run has successfully completed and the next run time
// is being persisted by the scheduler. If an error is returned, the error will be logged
// but the duration returned will still be used in scheduling. If a zero duration is returned
// the job will be scheduled to run again immediately.
NextRunIn(context.Context) (time.Duration, error)
// Name is the unique name of the job.
Name() string
// Description is the human readable description of the job.
Description() string
}
// JobStatus defines the struct that must be returned by the Job.Status() method.
type JobStatus struct {
// Completed and Total are used to indicate job progress,
// each job implementation will determine the definition of
// progress by calculating both Completed and Total.
Completed, Total int
}
func validateJob(j Job) error {
const op = "scheduler.validateJob"
if j == nil {
return errors.NewDeprecated(errors.InvalidParameter, op, "missing job")
}
if j.Name() == "" {
return errors.NewDeprecated(errors.InvalidParameter, op, "missing name")
}
if j.Description() == "" {
return errors.NewDeprecated(errors.InvalidParameter, op, "missing description")
}
return nil
}