-
Notifications
You must be signed in to change notification settings - Fork 35
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
Fixing WaitFor
support with Ollama model downloads
#260
Conversation
The lifecycle hook would get blocked if you used WaitFor on the model resource, as it wouldn't fire until the model was healthy, which it couldn't achieve. Refactored to use an event instead that relies on the server resource ready event. Had to turn the event into a non-blocking with Task.Run otherwise models couldn't be downloaded concurrently, as the events would run one at a time, waiting for model download completion before continuing on. Also took this time to refactor the AddModel method to have a few extension methods, making it a bit clearer as to what happens when. Fixes #256
Minimum allowed line rate is |
ResourceCommandState.Enabled : | ||
ResourceCommandState.Disabled, | ||
executeCommand: async context => | ||
builder.ApplicationBuilder.Eventing.Subscribe<ResourceReadyEvent>(builder.Resource.Parent, (@event, cancellationToken) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we subscribe to the ResourceReadyEvent
for a resource multiple times?
What happens when we have various models?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we can, they will fire in sequence though, which is why I use Task.Run
to execute the download, spawning a background job to download the model so that the event handler becomes non-blocking (originally I didn't do that and it would be blocking, which is not ideal).
Closes #256
PR Checklist
Other information
The lifecycle hook would get blocked if you used WaitFor on the model resource, as it wouldn't fire until the model was healthy, which it couldn't achieve. Refactored to use an event instead that relies on the server resource ready event.
Had to turn the event into a non-blocking with Task.Run otherwise models couldn't be downloaded concurrently, as the events would run one at a time, waiting for model download completion before continuing on.
Also took this time to refactor the AddModel method to have a few extension methods, making it a bit clearer as to what happens when.