Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[to-reply] feature: support saga multi type config #741

Open
wants to merge 8 commits into
base: feature/saga
Choose a base branch
from

Conversation

FinnTew
Copy link
Contributor

@FinnTew FinnTew commented Dec 15, 2024

What this PR does:

Supported multi-type configuration parser in saga mode, fixed some related problems, adjusted and improved related unit tests, and supplemented test data in yaml format.

Which issue(s) this PR fixes:

Fixes #734

Special notes for your reviewer:

All relevant unit tests have been completed and passed.

Does this PR introduce a user-facing change?:

`JSONStateMachineParser.Parse(content)` changed to `JSONStateMachineParser.Parse(configFilePath)`

Copy link
Contributor

@Code-Fight Code-Fight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apache License 要加上,其他的酌情考虑下

@@ -0,0 +1,127 @@
package parser
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要带上apache的License 头,参考别的文件copy一个,或者参考根目录的 goimports.sh 下面所有的文件都检查一下

@luky116
Copy link
Contributor

luky116 commented Dec 15, 2024

配置文件的解析,可以复用当前已有的逻辑
image


for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := parser.Parse(tt.configFilePath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里对字段的值进行断言?

@@ -115,16 +112,3 @@ func (stateMachineParser JSONStateMachineParser) isTaskState(stateType string) b
}
return false
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些不需要用了吗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StateMachineJsonObject 改为了 statemachine_config_parser 中的 StateMachineObject,给 json 和 yaml 共用,两种格式解析后的结构是一致的,这里的 Parser 实际是和配置文件格式无关的,所以感觉放在 config parser 中更合理一些

@Code-Fight
Copy link
Contributor

apache License 要在你所有新增的文件上加上,只要没有的,都要加上

@FinnTew
Copy link
Contributor Author

FinnTew commented Dec 16, 2024

apache License 要在你所有新增的文件上加上,只要没有的,都要加上

好的

// just use float64 to convert, json reader will read all number as float64
valueAsFloat64, ok := value.(float64)
if !ok {
// use float64 conversion when the configuration file is json, and use int conversion when the configuration file is yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it designed this way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because "encoding/json" package will convert all numerical values into float64 types when parsing json, but" yaml.v3" package will correspond to float64 and int types when parsing YAML, and the modification here is mainly to be compatible with the two formats, otherwise some errors will occur.

return &stateMachineObject, nil
}

type StateMachineObject struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a stateMachineJsonObject struct, maybe we can unify them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the StateMachineObject here is the original StateMachineJsonObject. Because the products of the two formats are basically consistent, I moved the definition of the structure to config parser and added a tag to be compatible with the two formats.

@luky116 luky116 changed the title feature: support saga multi type config [to-reply] feature: support saga multi type config Dec 21, 2024
var stateMachineJsonObject StateMachineJsonObject

err := json.Unmarshal([]byte(content), &stateMachineJsonObject)
func (stateMachineParser JSONStateMachineParser) Parse(configFilePath string) (statelang.StateMachine, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make interface and the impl has same param

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants