-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Azure/haitao/remove_v1
solving shared state via method receiver
- Loading branch information
Showing
26 changed files
with
929 additions
and
1,781 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,60 @@ | ||
package asyncjob | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
type JobErrorCode string | ||
|
||
const ( | ||
ErrPrecedentStepFailure JobErrorCode = "precedent step failed" | ||
ErrStepFailed JobErrorCode = "current step failed" | ||
ErrStepFailed JobErrorCode = "step failed" | ||
ErrStepNotInJob JobErrorCode = "trying to reference to a step not registered in job" | ||
) | ||
|
||
func (code JobErrorCode) Error() string { | ||
return string(code) | ||
} | ||
|
||
type JobError struct { | ||
Code JobErrorCode | ||
StepError error | ||
StepName string | ||
Message string | ||
Code JobErrorCode | ||
StepError error | ||
StepInstance StepInstanceMeta | ||
Message string | ||
} | ||
|
||
func newJobError(code JobErrorCode, message string) *JobError { | ||
return &JobError{Code: code, Message: message} | ||
} | ||
|
||
func newStepError(stepName string, stepErr error) *JobError { | ||
return &JobError{Code: ErrStepFailed, StepName: stepName, StepError: stepErr} | ||
func newStepError(code JobErrorCode, step StepInstanceMeta, stepErr error) *JobError { | ||
return &JobError{Code: code, StepInstance: step, StepError: stepErr} | ||
} | ||
|
||
func (je *JobError) Error() string { | ||
if je.Code == ErrStepFailed && je.StepError != nil { | ||
return fmt.Sprintf("step %q failed: %s", je.StepName, je.StepError.Error()) | ||
return fmt.Sprintf("step %q failed: %s", je.StepInstance.GetName(), je.StepError.Error()) | ||
} | ||
return je.Code.Error() + ": " + je.Message | ||
} | ||
|
||
func (je *JobError) Unwrap() error { | ||
return je.StepError | ||
} | ||
|
||
// RootCause track precendent chain and return the first step raised this error. | ||
func (je *JobError) RootCause() error { | ||
// this step failed, return the error | ||
if je.Code == ErrStepFailed { | ||
return je.StepError | ||
return je | ||
} | ||
|
||
// precendent step failure, track to the root | ||
if je.Code == ErrPrecedentStepFailure { | ||
precedentStepErr := &JobError{} | ||
if !errors.As(je.StepError, &precedentStepErr) { | ||
return je.StepError | ||
} | ||
return precedentStepErr.RootCause() | ||
} | ||
|
||
return je.Code | ||
// no idea | ||
return je | ||
} |
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 |
---|---|---|
@@ -1,15 +1,13 @@ | ||
module github.com/Azure/go-asyncjob | ||
module github.com/Azure/go-asyncjob/v2 | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/Azure/go-asyncjob/graph v0.2.0 | ||
github.com/Azure/go-asynctask v1.3.1 | ||
github.com/stretchr/testify v1.8.1 | ||
) | ||
|
||
require ( | ||
github.com/Azure/go-asyncjob/graph v0.2.0 // indirect | ||
github.com/Azure/go-asynctask v1.3.1 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/stretchr/objx v0.5.0 // indirect | ||
github.com/stretchr/testify v1.8.1 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.