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

Possible rules prototype #4246

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Possible rules prototype #4246

wants to merge 3 commits into from

Conversation

VeronikaSolovei9
Copy link
Contributor

No description provided.

Copy link
Contributor

@SyntaxNode SyntaxNode left a comment

Choose a reason for hiding this comment

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

Good approach. Recommend next steps are to flesh out the Rules engine tree structure with full path lookup and default support per the spec.

@@ -0,0 +1,53 @@
package optimizationmodule
Copy link
Contributor

Choose a reason for hiding this comment

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

The real location should be "modules\prebid\optimization" with the package name "optimization".

}

// will be used in Build rules trie
func NewFunction(name string, params []string) Function {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should return an error, to allow the function builders to validate their input and return an error or warning.


// will be used in Build rules trie
func NewFunction(name string, params []string) Function {
switch name {
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll want to make this case insensitive. Recommend converting to lowercase and having all the cases expressed in lowercase too.

case "setDeviceIP":
return NewSetDevIp(params)
default:
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be at least a warning, if a function name is not found / supported.

return "yes", nil
}
return "no", nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good. We can make the yes / no constants to reuse in other functions... or should these be "true" and "false"?


func (sdip *SetDeviceIp) Call(rw *openrtb_ext.RequestWrapper) (string, error) {
rw.Device.IP = sdip.IP
return "", nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This will need to use the modifier pattern. Instead of making the change right here, it needs to return a change set mutation.

type Node struct {
Function Function
// string because "rules": [{ "conditions": ["true", "false"],
Children map[string]*Node
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the nodes be values instead of pointers?

IP: "0.0.0.0",
},
}}
err := rules.Execute(rw)
Copy link
Contributor

Choose a reason for hiding this comment

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

The params first need to be extracted, then given to Execute, and then Execute will use the params to locate a node. This will involve some backtracking behavior for defaults.

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

Successfully merging this pull request may close these issues.

2 participants