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

refactor: builtin actions #537

Merged
merged 2 commits into from
Oct 11, 2023
Merged

refactor: builtin actions #537

merged 2 commits into from
Oct 11, 2023

Conversation

mkanoor
Copy link
Contributor

@mkanoor mkanoor commented Jun 12, 2023

Each action is a separate class
Allows for us to share code between different actions in a Helper class
Each action can be tested independently by injecting the required events

Screenshot 2023-08-10 at 9 39 28 AM

@mkanoor mkanoor force-pushed the refactor_actions branch 6 times, most recently from 51d3968 to bb32d6f Compare June 12, 2023 21:33
@mkanoor mkanoor force-pushed the refactor_actions branch from bb32d6f to d829fb9 Compare June 13, 2023 14:41
Copy link
Contributor

@Alex-Izquierdo Alex-Izquierdo left a comment

Choose a reason for hiding this comment

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

Is there a reason to use the __call__ internal method?

I'm concerned about the approach to using the internal method __call__ to run the logic of the action. I feel is not a good usage of this method and that method will be executed every time the object is called. It obfuscates the interface of the action, specially if we want to support pluggable actions. I feel the action should be executed through an ad-hoc "run" method. This seems to be the same pattern followed by plugins and modules in ansible.

ansible_rulebook/action/control.py Show resolved Hide resolved
@benthomasson
Copy link
Contributor

This conflicts with having actions be simple functions. Functions are easier to test since they have no internal state. It also makes a plugin architecture harder since plugins have to inherit from a base class. I am generally against inheritance for code reuse. I prefer composition to inheritance using the delegation pattern: https://en.wikipedia.org/wiki/Delegation_pattern.

@mkanoor
Copy link
Contributor Author

mkanoor commented Jun 30, 2023

@benthomasson Please re-review I have used a Helper class to keep the shared code between the different actions.

@mkanoor mkanoor changed the title Refactor actions refactor: Refactor built in actions Aug 4, 2023
@mkanoor mkanoor changed the title refactor: Refactor built in actions refactor: built in actions Aug 4, 2023
@mkanoor mkanoor changed the title refactor: built in actions refactor: builtin actions Aug 4, 2023
@mkanoor mkanoor force-pushed the refactor_actions branch 2 times, most recently from f99cbc1 to 3d8e4f8 Compare August 9, 2023 15:28
@mkanoor mkanoor force-pushed the refactor_actions branch 4 times, most recently from 9cb115e to 7ae8041 Compare August 21, 2023 21:09
@mkanoor mkanoor force-pushed the refactor_actions branch 5 times, most recently from a1f103c to 170816d Compare September 28, 2023 15:49
@mkanoor mkanoor force-pushed the refactor_actions branch 2 times, most recently from 05a6141 to c649a9d Compare October 10, 2023 17:01
Each action is a separate class
Allows for us to share code between actions
Copy link
Contributor

@Alex-Izquierdo Alex-Izquierdo left a comment

Choose a reason for hiding this comment

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

Isn't this PR leaving dead code in the repo?

ansible_rulebook/action/post_event.py Show resolved Hide resolved
ansible_rulebook/action/run_job_template.py Show resolved Hide resolved
ansible_rulebook/action/run_module.py Show resolved Hide resolved
@mkanoor
Copy link
Contributor Author

mkanoor commented Oct 11, 2023

Isn't this PR leaving dead code in the repo?

@Alex-Izquierdo Yes it will be removed in a different PR, since this PR was open for a while deleting the file and rebasing every time was a challenge.

#598

@mkanoor mkanoor merged commit bddc7ca into ansible:main Oct 11, 2023
7 checks passed
mkanoor added a commit that referenced this pull request Oct 16, 2023
Since we have refactored actions we don't need the old builtin.py any
more.
Related to PR #537
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.

4 participants