feat: impl new supervisor traits k8s#2055
Conversation
bc538fd to
21b7be4
Compare
| where | ||
| I: IntoIterator<Item = StartedThreadContext<()>>, | ||
| { | ||
| fn stop(self) -> Result<(), ThreadContextStopperError> { |
There was a problem hiding this comment.
Cool! I think it reads better, and we can improve it a little bit more I think. What about adding the logs directly to the stop_blocking function?
/// It sends a stop signal and waits until the thread handle is joined.
pub fn stop_blocking(self) -> Result<T, ThreadContextStopperError> {
...
self.join_thread()
.inspect(|_| debug!("Thread {thread_name} stopped"))
.inspect_err(|e| error!("Error stopping thread {thread_name}: {e}"))
}
fn stop(self) -> Result<(), ThreadContextStopperError> {
let stopped_threads = self
.into_iter()
.map(|ctx| ctx.stop_blocking())
.collect::<Vec<_>>();
stopped_threads
.into_iter()
// Return first err
.try_for_each(identity)
}Also, using some variables to differentiate steps might help. But this is purely subjective.
There was a problem hiding this comment.
I was initially against it to not change much of the existing implementation, but I can see the advantage and finally moved the logs as you suggested, thanks!
There was a problem hiding this comment.
Maybe you can have a separate PR with these improvements if you want. I think it's more work.
There was a problem hiding this comment.
The logs were already moved to the stop_blocking and there's a bit of comment to indicate what exactly identity is for. Let me know if you'd like something else!
gsanchezgavier
left a comment
There was a problem hiding this comment.
could you include some PR description ?
style: move implementations to separate modules
f73b753 to
55009c1
Compare
Certainly! 🚀 |
| type ApplyError = ApplyError; | ||
| type StopError = ThreadContextStopperError; | ||
|
|
||
| fn apply(self, effective_agent: EffectiveAgent) -> Result<Self, Self::ApplyError> { |
There was a problem hiding this comment.
I like the new approach. We avoid having a special "try_build_new_supervisor" or something like that as before. Cool!!!
| } | ||
| } | ||
|
|
||
| // Clone the k8s_client on each build. |
There was a problem hiding this comment.
it is an arc right? if so perhaps i would remove this comment that brings some uncertainty
There was a problem hiding this comment.
Yeah it's an arc, I'll delete the comment or specify we clone the reference
gsanchezgavier
left a comment
There was a problem hiding this comment.
Cool thanks!, I just left a question
| // Return first err (`identity` acts as a "pass-through" here, | ||
| // so the first Err interrupts the iteration) |
There was a problem hiding this comment.
🤔 is it ok to stop , wouldn't that leak threads ?
There was a problem hiding this comment.
Yeah the threads are all stopped in the previous binding let stopped_threads, this only selects the first error among the results (a behavior similar to the one we had before, perhaps it's time to aggregate the errors and return them all instead?)
There was a problem hiding this comment.
ohh i just see these are the returned errors of the joins !
perhaps it's time to aggregate the errors and return them all instead?
It looks enough as it is now for me 👍
| // Return first err (`identity` acts as a "pass-through" here, | ||
| // so the first Err interrupts the iteration) |
There was a problem hiding this comment.
ohh i just see these are the returned errors of the joins !
perhaps it's time to aggregate the errors and return them all instead?
It looks enough as it is now for me 👍
Implements the new traits defined on #2048 for the Kubernetes running mode of AC. The implementation actually stops and destroys the running supervisor and starts a new supervisor under the
applymethod (making it a bit of a misnomer). This is mainly a matter of thread management ergonomics, but this could be reworked if desired (this PR or later iterations) by adding some data sharing.Checklist
docsis aligned with the change.CONTRIBUTING.md.log level guidelines.