|
|
|
|
@ -26,7 +26,7 @@ func (r *Repository) RunJobs(ctx context.Context, serverId string, opt ...Option
|
|
|
|
|
var runs []*Run
|
|
|
|
|
_, err := r.writer.DoTx(ctx, db.StdRetryCnt, db.ExpBackoff{},
|
|
|
|
|
func(r db.Reader, w db.Writer) error {
|
|
|
|
|
rows, err := r.Query(ctx, runJobsQuery, []interface{}{serverId, opts.withRunJobsLimit})
|
|
|
|
|
rows, err := w.Query(ctx, runJobsQuery, []interface{}{serverId, opts.withRunJobsLimit})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrap(err, op)
|
|
|
|
|
}
|
|
|
|
|
@ -65,7 +65,7 @@ func (r *Repository) UpdateProgress(ctx context.Context, runId string, completed
|
|
|
|
|
run.PrivateId = runId
|
|
|
|
|
_, err := r.writer.DoTx(ctx, db.StdRetryCnt, db.ExpBackoff{},
|
|
|
|
|
func(r db.Reader, w db.Writer) error {
|
|
|
|
|
rows, err := r.Query(ctx, updateProgressQuery, []interface{}{completed, total, runId})
|
|
|
|
|
rows, err := w.Query(ctx, updateProgressQuery, []interface{}{completed, total, runId})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrap(err, op)
|
|
|
|
|
}
|
|
|
|
|
@ -105,7 +105,8 @@ func (r *Repository) UpdateProgress(ctx context.Context, runId string, completed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CompleteRun updates the Run repository entry for the provided runId.
|
|
|
|
|
// It sets the status to 'completed' and updates the run's EndTime to the current database time.
|
|
|
|
|
// It sets the status to 'completed', updates the run's EndTime to the current database
|
|
|
|
|
// time, and sets the completed and total counts.
|
|
|
|
|
// CompleteRun also updates the Job repository entry that is associated with this run,
|
|
|
|
|
// setting the job's NextScheduledRun to the current database time incremented by the nextRunIn
|
|
|
|
|
// parameter.
|
|
|
|
|
@ -114,7 +115,7 @@ func (r *Repository) UpdateProgress(ctx context.Context, runId string, completed
|
|
|
|
|
// or interrupted), any future calls to CompleteRun will return an error with Code
|
|
|
|
|
// errors.InvalidJobRunState.
|
|
|
|
|
// All options are ignored.
|
|
|
|
|
func (r *Repository) CompleteRun(ctx context.Context, runId string, nextRunIn time.Duration, _ ...Option) (*Run, error) {
|
|
|
|
|
func (r *Repository) CompleteRun(ctx context.Context, runId string, nextRunIn time.Duration, completed, total int, _ ...Option) (*Run, error) {
|
|
|
|
|
const op = "job.(Repository).CompleteRun"
|
|
|
|
|
if runId == "" {
|
|
|
|
|
return nil, errors.New(errors.InvalidParameter, op, "missing run id")
|
|
|
|
|
@ -124,7 +125,11 @@ func (r *Repository) CompleteRun(ctx context.Context, runId string, nextRunIn ti
|
|
|
|
|
run.PrivateId = runId
|
|
|
|
|
_, err := r.writer.DoTx(ctx, db.StdRetryCnt, db.ExpBackoff{},
|
|
|
|
|
func(r db.Reader, w db.Writer) error {
|
|
|
|
|
rows, err := r.Query(ctx, completeRunQuery, []interface{}{runId})
|
|
|
|
|
// TODO (lcr 07/2021) this can potentially overwrite completed and total values
|
|
|
|
|
// persisted by the scheduler's monitor jobs loop.
|
|
|
|
|
// Add an on update sql trigger to protect the job_run table, once progress
|
|
|
|
|
// values are used in the critical path.
|
|
|
|
|
rows, err := w.Query(ctx, completeRunQuery, []interface{}{completed, total, runId})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrap(err, op)
|
|
|
|
|
}
|
|
|
|
|
@ -153,7 +158,7 @@ func (r *Repository) CompleteRun(ctx context.Context, runId string, nextRunIn ti
|
|
|
|
|
return errors.New(errors.InvalidJobRunState, op, fmt.Sprintf("job run was in a final run state: %v", run.Status))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rows1, err := r.Query(ctx, setNextScheduledRunQuery, []interface{}{int(nextRunIn.Round(time.Second).Seconds()), run.JobPluginId, run.JobName})
|
|
|
|
|
rows1, err := w.Query(ctx, setNextScheduledRunQuery, []interface{}{int(nextRunIn.Round(time.Second).Seconds()), run.JobPluginId, run.JobName})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrap(err, op, errors.WithMsg(fmt.Sprintf("failed to set next scheduled run time for job: %s", run.JobName)))
|
|
|
|
|
}
|
|
|
|
|
@ -183,13 +188,14 @@ func (r *Repository) CompleteRun(ctx context.Context, runId string, nextRunIn ti
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FailRun updates the Run repository entry for the provided runId.
|
|
|
|
|
// It sets the status to 'failed' and updates the run's EndTime to the current database time.
|
|
|
|
|
// It sets the status to 'failed' and updates the run's EndTime to the current database
|
|
|
|
|
// time, and sets the completed and total counts.
|
|
|
|
|
//
|
|
|
|
|
// Once a run has been persisted with a final run status (completed, failed
|
|
|
|
|
// or interrupted), any future calls to FailRun will return an error with Code
|
|
|
|
|
// errors.InvalidJobRunState.
|
|
|
|
|
// All options are ignored.
|
|
|
|
|
func (r *Repository) FailRun(ctx context.Context, runId string, _ ...Option) (*Run, error) {
|
|
|
|
|
func (r *Repository) FailRun(ctx context.Context, runId string, completed, total int, _ ...Option) (*Run, error) {
|
|
|
|
|
const op = "job.(Repository).FailRun"
|
|
|
|
|
if runId == "" {
|
|
|
|
|
return nil, errors.New(errors.InvalidParameter, op, "missing run id")
|
|
|
|
|
@ -199,7 +205,11 @@ func (r *Repository) FailRun(ctx context.Context, runId string, _ ...Option) (*R
|
|
|
|
|
run.PrivateId = runId
|
|
|
|
|
_, err := r.writer.DoTx(ctx, db.StdRetryCnt, db.ExpBackoff{},
|
|
|
|
|
func(r db.Reader, w db.Writer) error {
|
|
|
|
|
rows, err := r.Query(ctx, failRunQuery, []interface{}{runId})
|
|
|
|
|
// TODO (lcr 07/2021) this can potentially overwrite completed and total values
|
|
|
|
|
// persisted by the scheduler's monitor jobs loop.
|
|
|
|
|
// Add an on update sql trigger to protect the job_run table, once progress
|
|
|
|
|
// values are used in the critical path.
|
|
|
|
|
rows, err := w.Query(ctx, failRunQuery, []interface{}{completed, total, runId})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrap(err, op)
|
|
|
|
|
}
|
|
|
|
|
@ -263,7 +273,7 @@ func (r *Repository) InterruptRuns(ctx context.Context, interruptThreshold time.
|
|
|
|
|
var runs []*Run
|
|
|
|
|
_, err := r.writer.DoTx(ctx, db.StdRetryCnt, db.ExpBackoff{},
|
|
|
|
|
func(r db.Reader, w db.Writer) error {
|
|
|
|
|
rows, err := r.Query(ctx, query, args)
|
|
|
|
|
rows, err := w.Query(ctx, query, args)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrap(err, op)
|
|
|
|
|
}
|
|
|
|
|
|