Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jobstest: move FakeResumer to jobstest
Release note: None
- Loading branch information
1 parent
060b1bc
commit 1b00425
Showing
7 changed files
with
100 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package jobstest | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb" | ||
"github.com/cockroachdb/cockroach/pkg/sql/isql" | ||
) | ||
|
||
// FakeResumer calls optional callbacks during the job lifecycle. | ||
type FakeResumer struct { | ||
OnResume func(context.Context) error | ||
FailOrCancel func(context.Context) error | ||
Success func() error | ||
PauseRequest func(ctx context.Context, planHookState interface{}, txn isql.Txn, progress *jobspb.Progress) error | ||
TraceRealSpan bool | ||
} | ||
|
||
func (d FakeResumer) ForceRealSpan() bool { | ||
return d.TraceRealSpan | ||
} | ||
|
||
func (d FakeResumer) DumpTraceAfterRun() bool { | ||
return true | ||
} | ||
|
||
func (d FakeResumer) Resume(ctx context.Context, _ interface{}) error { | ||
if d.OnResume != nil { | ||
if err := d.OnResume(ctx); err != nil { | ||
return err | ||
} | ||
} | ||
if d.Success != nil { | ||
return d.Success() | ||
} | ||
return nil | ||
} | ||
|
||
func (d FakeResumer) OnFailOrCancel(ctx context.Context, _ interface{}, _ error) error { | ||
if d.FailOrCancel != nil { | ||
return d.FailOrCancel(ctx) | ||
} | ||
return nil | ||
} | ||
|
||
func (d FakeResumer) CollectProfile(_ context.Context, _ interface{}) error { | ||
return nil | ||
} | ||
|
||
func (d FakeResumer) OnPauseRequest( | ||
ctx context.Context, execCtx interface{}, txn isql.Txn, details *jobspb.Progress, | ||
) error { | ||
if d.PauseRequest == nil { | ||
return nil | ||
} | ||
return d.PauseRequest(ctx, execCtx, txn, details) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.