Releases: TanmoySG/go-steps
v0.3.0-beta
Whats New in v0.3.0-beta
?
Added the feature to pick between previous step returned values, or current step's arguments or use both as arguments to run the current step.
var steps = gosteps.Step{
Name: "add",
Function: funcs.Add,
StepArgs: []interface{}{2, 3},
NextStep: gosteps.Steps{
Name: "sub",
Function: funcs.Sub,
StepArgs: []interface{}{4, 6},
UseArguments: gosteps.CurrentStepArgs,
},
}
Available configurations for UseArguments
// only previous step return will be passed to current step as arguments
PreviousStepReturns stepArgChainingType = "PreviousStepReturns"
// only current step arguments (StepArgs) will be passed to current step as arguments
CurrentStepArgs stepArgChainingType = "CurrentStepArgs"
// both previous step returns and current step arguments (StepArgs) will be passed
// to current step as arguments - previous step returns, followed by current step args,
PreviousReturnsWithCurrentStepArgs stepArgChainingType = "PreviousReturnsWithCurrentStepArgs"
// both previous step returns and current step arguments (StepArgs) will be passed
// to current step as arguments - current step args, followed by previous step returns
CurrentStepArgsWithPreviousReturns stepArgChainingType = "CurrentStepArgsWithPreviousReturns"
Additionally renamed some fields like AdditionalArgs
is now StepArgs
. Defined types for Step Function, Step Chaining Type, etc. Also refactored and added Unit Tests.
v0.2.0-beta
Changes
- Updated Step type
- Updated code to use new Step type
New Types
- Step Type with new field
- PossibleNextSteps : List of steps
- NextStep (instead of NextSteps)
GoSteps
GoSteps is a go library that helps in running functions as steps and reminds you to step out and get active (kidding!).
The idea behind gosteps
is to define set of functions as steps-chain (kind of a linked list) and execute them in a sequential fashion by piping output (other than error) from previous step, as arguments, into the next steps (not necessarily using the args).
Usage
The Step
type contains the requirments to execute a step function and move to next one.
type Step struct {
Name StepName
Function interface{}
AdditionalArgs []interface{}
NextStep *Step
PossibleNextSteps PossibleNextSteps
NextStepResolver interface{}
ErrorsToRetry []error
StrictErrorCheck bool
SkipRetry bool
MaxAttempts int
RetrySleep time.Duration
}
Field | Description |
---|---|
Name | Name of step |
Function | The function to execute |
AdditionalArgs | any additional arguments need to pass to te step |
NextStep | Next Step for the current step. If next step needs to be conditional dont set this and use PossibleNextSteps field instead |
PossibleNextSteps | Candidate functions for next step (pick from multiple possible next steps based on condition) |
NextStepResolver | A function that returns the step name, based on conditions, that is used to pick the NextStep from PossibleNextSteps |
ErrorsToRetry | A list of error to retry step for |
StrictErrorCheck | If set to true exact error is matched, else only presence of error is checked |
SkipRetry | If set to true step is not retried for any error |
MaxAttempts | Max attempts are the number of times the step is tried (first try + subsequent retries). If not set, it'll run 100 times |
RetrySleep | Sleep duration (type time.Duration) between each re-attempts |
More at README.md
v0.1.1-beta
[Fix] v0.1.1-beta
Fix/Handle execution for no initial/entry step [#4]
In v0.1.0-beta if there are no steps (no initial or subsequent steps) then the Execute() functions panics and exits. To Fix this adding a simple check to see if (initial) steps are not empty. If it is then no error is returned or no panics are caused.
if len(steps) == 0 {
return nil, nil
}
Commit: 9624cf3
What's Changed
Full Changelog: v0.1.0-beta...v0.1.1-beta
[v0.1.0-beta] GoSteps Initial Library
GoSteps
GoSteps is a go library that helps in running functions as steps and reminds you to step out and get active (kidding!).
The idea behind gosteps
is to define set of functions as steps-chain (kind of a linked list) and execute them in a sequential fashion by piping output (other than error) from previous step, as arguments, into the next steps (not necessarily using the args).
Usage
The Step
type contains the requirments to execute a step function and move to next one.
type Step struct {
Name StepName
Function interface{}
AdditionalArgs []interface{}
NextSteps []Step
NextStepResolver interface{}
ErrorsToRetry []error
StrictErrorCheck bool
SkipRetry bool
MaxAttempts int
RetrySleep time.Duration
}
Field | Description |
---|---|
Name | Name of step |
Function | The function to execute |
AdditionalArgs | any additional arguments need to pass to te step |
NextSteps | Candidate functions for next step (multiple next steps in-case of condition based execution) |
NextStepResolver | A function that returns the step name, based on conditions, that is used to pick the nextStep from NextSteps |
ErrorsToRetry | A list of error to retry step for |
StrictErrorCheck | If set to true exact error is matched, else only presence of error is checked |
SkipRetry | If set to true step is not retried for any error |
MaxAttempts | Max attempts are the number of times the step is tried (first try + subsequent retries). If not set, it'll run 100 times |
RetrySleep | Sleep duration (type time.Duration) between each re-attempts |