-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scanresult): resource cleanup state refactor
- Loading branch information
1 parent
3eef08c
commit 32281e6
Showing
9 changed files
with
310 additions
and
171 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,25 @@ | ||
package models | ||
|
||
import "fmt" | ||
|
||
type ResourceCleanupStateMachine map[ResourceCleanupStatusState][]ResourceCleanupStatusState | ||
|
||
var ResourceCleanupStatusStateValidTransitions = ResourceCleanupStateMachine{ | ||
ResourceCleanupStatusStatePending: { | ||
ResourceCleanupStatusStateSkipped, | ||
ResourceCleanupStatusStateFailed, | ||
ResourceCleanupStatusStateDone, | ||
}, | ||
} | ||
|
||
func (rcs *ResourceCleanupStatus) UpdateState(toState ResourceCleanupStatusState) error { | ||
transitions := ResourceCleanupStatusStateValidTransitions[*rcs.State] | ||
for _, transition := range transitions { | ||
if transition == toState { | ||
rcs.State = &toState | ||
return nil | ||
} | ||
} | ||
|
||
return fmt.Errorf("invalid transition, from: %s to: %s", *rcs.State, toState) | ||
} |
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.