Releases: TanmoySG/go-steps
v1.1.0
Features in this release
Logging Enhancements:
- Introduced a new logging mechanism using the
zerolog
package. The logger can be initialized withgosteps.NewGoStepsLogger
and used within the context (go_step_logger.go
). - Added the ability to log messages within step functions using the
ctx.Log()
method (go_step_context.go
). [1] [2]
Error Handling Improvements:
- Replaced the
StepError
type with the standarderror
type for better compatibility and simplicity (README.md
,go_step_result.go
,go_step_types.go
). [1] [2] - Updated the
StepResult
struct and related methods to handle standard errors (go_step_result.go
).
Example Code Updates:
- Enhanced the example in
example/multistep-example/main.go
to demonstrate the new logging and error handling features, including retry logic and logging within steps. [1] [2] [3] [4] [5] [6] [7]
Documentation Updates:
- Updated the
README.md
to reflect the changes in error handling and to include examples of the new logging functionality. [1] [2] [3]
Miscellaneous:
- Updated the
go.mod
file to include thezerolog
package and other dependencies.
This pull request introduces significant changes to the go-steps
library, including updates to the documentation and the addition of new examples, functions, and types for better functionality and error handling. The most important changes include updates to the README.md
, new examples demonstrating the use of the library, and the introduction of new types and constants.
Documentation Updates:
README.md
: Updated the note about breaking changes ingo-steps
v1 and provided guidance on how to continue using v0. Removed the "Help" section. [1] [2]
New Examples:
example/v0/dynamic-steps-example/main.go
: Added a new example demonstrating dynamic step chaining and execution.example/v0/multistep-example/main.go
: Added a new example demonstrating multi-step execution with conditional next steps and error handling.
New Functions and Types:
v0/go_step_types.go
: Introduced new types (StepName
,StepFn
,PossibleNextSteps
,Step
,stepArgChainingType
) to define steps and their configurations.v0/go_steps_constants.go
: Added constants and variables for default and maximum step attempts, and argument chaining types.
Step Execution and Error Handling:
v0/go_steps.go
: Implemented theExecute
method for theStep
type, including logic for step execution, argument resolution, and error handling with retries.v0/go_steps_errors.go
: Added error messages for unresolved steps.
Testing:
v0/go_steps_test.go
: Added tests for step argument resolution, next step resolution, and retry logic.
v1.0.2
What's Changed
A step would retry for all errors for MaxRunAttempts even when step moved out of Error State.
Cause
shouldRetry
returns true ifstep.StepOpts.RetryAllErrors
is set to true, without checking ifstep.stepResult.StepState
is in Error state.
if step.StepOpts.RetryAllErrors {
return true
}
Fix
- Adding check for
step.stepResult.StepState
to be StepStateError in addition to the RetryAllErrors fixes this bug.
if step.stepResult.StepState == StepStateError && step.StepOpts.RetryAllErrors {
return true
}
In addition step.StepOpts.MaxRunAttempts == step.stepRunProgress.runCount
has been removed from shouldExit
This pull request includes changes to the go_steps.go
file to enhance the retry and exit logic for steps. The most important changes include adding a condition to check the step state before retrying and refactoring the exit logic to use a switch statement.
Enhancements to retry logic:
go_steps.go
: Updated theshouldRetry
method to include a condition that checks if the step state isStepStateError
before retrying.
Refactoring exit logic:
go_steps.go
: Refactored theshouldExit
method to use a switch statement for better readability and removed the redundant return statement.
Full Changelog: v1.0.1...v1.0.2
v1.0.1
v1.0.0-beta
GoSteps - v1
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 chain-of-steps and execute them in a sequential fashion.
Usage
Functions
that needs execution are defined as a Step
, and each step is a part of a collection of multiple Steps called Branch
, that runs sequentially. Each step can have multiple Branches
as possible next steps, and the branch to be executed is determined based on a ResolverFuntion
of that step.
The v1 introduces breaking changes to how steps are defined, GoSteps types, context and execution.
Read more here.
Note
go-steps v1 is a breaking change and older v0 models wont work with the new version. For v0 documentation, examples refer to v0.3.0-beta documentation or v0 guide here.
This pull request introduces significant changes to the go-steps
library, focusing on refactoring the step execution logic, improving context management, and enhancing error handling. The most important changes include the removal of the dynamic steps example, the refactoring of the multistep example, the introduction of a new context management system, and various improvements to step execution and result handling.
Refactoring and Improvements:
example/dynamic-steps-example/main.go
: Removed the dynamic steps example to simplify the codebase.example/multistep-example/main.go
: Refactored the multistep example to use the new context management system and improved step execution logic.
Context Management:
go_step_context.go
: Introduced a new context management system (GoStepsCtx
) to handle step data and progress more effectively.
Step Execution and Result Handling:
go_step_result.go
: Added new types and methods for handling step results and states, includingStepResult
,StepState
, and various helper functions.go_steps.go
: Refactored the core step execution logic to support the new context management and result handling systems.
Other Changes:
go.mod
: Removed unnecessary dependencies to clean up the module file.go_steps_constants.go
: Removed unused constants related to step argument chaining.go_steps_errors.go
: Removed unused error variables.
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 |