-
Notifications
You must be signed in to change notification settings - Fork 29
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 service/daemon code to be usable outside of Ubic framework #38
Comments
Ok, new plan which ties everything together:
The point is so separate service-tree features (code from Ubic and Ubic::Cmd) and services further. So we will have pure services with start/stop/status methods, and then we will have complete services which update persistent status, support LSB methods like I know the example looks complicated and over-engineered, but we can add syntax sugar later. We can't use roles, though. There isn't any roles implementation which can be applied to objects instead of classes without causing memory leaks. Because perl doesn't have anonymous classes.
|
Wrappers will be useful outside of the scope of this task too, of course. |
I was wrong. |
it's called a decorator, not a wrapper, usually. plus I'd make ->new do the wrapping, otherwise ->wrap is going to have to produce a new object. nothing wrong with FooWrapper->new(service => $service, other_option => 'SPOON'); |
Yeah, I know what decorators are. The reason I'm not using this word is because I still can go with roles instead of delegation. The reason I chose
(Multiservice is an object representing the subtree of services, and wrapped multiservice should apply given wrapper to each subservice someone asks from it. Though we can avoid two objects per wrapper if we parameterize multiservice with class name and options hashref.) What puzzles me more is the painful decorators vs roles choice. DecoratorsIf I go with decorators, they'll have to delegate each I could implement some kind of infrastructure which delegates every method tagged in some way (with method attributes?), but I really don't want to accidentally reinvent the new object system here :) RolesWith roles, there are different problems. This is how I imagine the service configuration should look like, whatever we choose for implementation:
(I chose YAML for this example, but the similar thing can be done in perl) So, issue 1: I need parameterized roles, and I can't use Moose. Issue 2: wrappers application order can be important. I'm pretty sure both Moose and Moo will do-what-I-expect if I apply roles one-by-one, but relying on roles ordering is still considered a sin, right? Issue 3: of course roles and decorators are totally different in their behavior when the base class calls its own method. I'm still not sure which behavior I need, because I didn't wrote any code yet, but decorators look saner to me in this aspect. PS: Whatever I choose, final implementation should be easy to use for those who want to write a new wrapper. |
your argument wrt multiservice is incoherent; I think you're imagining problems that don't exist depending on the implementation. building a decorator is easy given (handles => 'NameOfRole') Package::Variant gives you a parameterized role like thing, but simply asserting "I need parameterized roles" isn't useful. I think "jam everything onto the service object" is likely the wrong answer here, and decorators built -using- roles is going to be rather nicer. equally, I don't really see how PortCheck or MemoryCheck is actually a wrapper; the locking thing is but they aren't - don't try and smash those two concepts together, it'll only make you cry. |
Yes, you're right. There are many ways to do it. Passing sub {} is another.
Yes! That's what I thought too after writing my last comment.
But I don't agree with this one. How else can I implement these features? Invent some kind of status check stack?
I agree that *Check examples is just a matter of adding Thank you for your comments, it's all much cleaner now :) |
@shadowcat-mst Damn, it's possible that you're right about Checks not being wrappers after all. |
the crucial one is that MemoryCheck is actually an instruction to the watchdog to load a particular plugin, which seems to me to not be the same class of problem. if PortCheck is "how to test if the service is up" then maybe that one -is-, but in that case PortCheck and MemoryCheck shouldn't have such similar names |
Oh right. I'm always forgetting about this one. |
One possible plan for refactoring: https://gist.github.com/b7a2ab5ae45df5847682
Alternatively, we can move all
Ubic::Daemon
code toDaemon::Control
as patches and then portUbic::Daemon
to useDaemon::Control
.The text was updated successfully, but these errors were encountered: