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

Fix allowedVmSizes #210

Merged
merged 11 commits into from
May 2, 2023
Merged

Fix allowedVmSizes #210

merged 11 commits into from
May 2, 2023

Conversation

jsaun
Copy link
Contributor

@jsaun jsaun commented Apr 27, 2023

AllowedVmSizes isn't currently working after some recent refactor. The allowed vm list was being set up in the constructor before the DoOnceAtStartUpService service has had a chance to run and parse the file.

Copy link
Collaborator

@BMurri BMurri left a comment

Choose a reason for hiding this comment

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

The technique used here affords a way to delay the start of a subsequent background service in order to ensure that all needed initialization has been performed.

When using the IOptions pattern, its an anti-pattern to hold onto IConfiguration unless your code is actively changing configuration values.

My honest opinion is that DoOnceAtStartUpService is an anti-pattern by itself, and the operations performed here should be called from either Program.cs or Startup.cs, but I'm not going to litigate that here.

@jsaun
Copy link
Contributor Author

jsaun commented Apr 28, 2023

I'm not quite following how you could use .Wait() in the Startup ConfigureServices method to hold off the batchscheduler singleton until after DoOnceAtStartUpService has run.

I don't have enough experience with IOptions, why is it an anti-pattern to hold onto IConfiguration. It looks like one of the first examples in Microsoft docs is doing just that: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-7.0#bind-hierarchical-configuration

@BMurri
Copy link
Collaborator

BMurri commented Apr 28, 2023

That first example is explicitly NOT the dependency injection example. The second example is explicitly is.

The idea with the Wait is to prevent subsequent services from starting until the required initialization code has completed (so, effectively turning a Task return into the equivalent of a void return, where the return doesn't happen until the method truly has completed). My suggestion was to apply it in the DoOnceAtStartUpService itself if a means of performing the initialization could not be easily performed in the Program or Startup classes.

@MattMcL4475 MattMcL4475 added this to the 4.3.0 milestone Apr 28, 2023
@jsaun jsaun force-pushed the jsaun/fix-allowed-vm-sizes branch from d609c0c to 7d68c9a Compare April 28, 2023 23:22
namespace TesApi.Web
{
/// <summary>
/// Hosted service that executes one-time set up tasks at start up.
Copy link
Collaborator

Choose a reason for hiding this comment

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

should fix this comment to be relevant too

private Task firstTask;

/// <summary>
/// Hosted service that executes one-time set-up tasks at start up.
Copy link
Collaborator

Choose a reason for hiding this comment

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

should fix this comment to be relevant too

@jsaun jsaun merged commit 84402e8 into main May 2, 2023
@jsaun jsaun deleted the jsaun/fix-allowed-vm-sizes branch May 2, 2023 01:19
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.

3 participants