SQL Database can't wait on a resource
afscrome opened this issue · 3 comments
I'd like to have a SQL Database wait on the SQL server, and in turn have apps wait on that database
var sql = builder.AddSqlServer("Sql").WithHealthCheck();
var db = sql.AddDatabase("Db").WaitFor(sql);
// Yes, I know this isn't an app, but
var app = builder.AddRedis("app").WaitFor(db);
await builder.Build().RunAsync();
This currently doesn't work. From stepping through the code, the EnvironmentCallbackAnnotation
callback never gets executed - presumably because the SQL database is not an executable resource.
For now I can work around this by explicitly adding a health check to the database, but it would feel more natural if we could model this as the DB depending on SQL. It would also provide clearer hints in the Aspire Dashboard - right now, whilst the DB health checks are running, both SQL Server and the database show as "Running", so it's not entirely clear why the app isn't starting. If the DB was waiting on SQL, then the DB resoruce would show as "Starting" until the SQL Server health checks pased.
var sql = builder.AddSqlServer("Sql").WithHealthCheck();
var db = sql.AddDatabase("Db").WaitFor(sql).WithHealthCheck();
This isn't possible today because of what you mentioned, we're hacking the environment variable callback to wait on resources. Databases are custom resources that implement IResourceWithConnectionString
.
Instead, I can make this work:
var sql = builder.AddSqlServer("Sql").WithHealthCheck();
var db = sql.AddDatabase("Db");
// Yes, I know this isn't an app, but
var app = builder.AddRedis("app").WaitFor(db);
await builder.Build().RunAsync();
Databases have a parent SQL resource, I can find the health check on the parent resource and use that if none is on the child.
It would also provide clearer hints in the Aspire Dashboard - right now, whilst the DB health checks are running, both SQL Server and the database show as "Running", so it's not entirely clear why the app isn't starting. If the DB was waiting on SQL, then the DB resoruce would show as "Starting" until the SQL Server health checks pased.
Agree this would be ideal but that would require changes to the core.
Fixed in aa9f9d5. Any resources that wait on the database will automagically use the sql server health check if defined. Nearest health check will win.
Awesome - that looks great. Will give it a go tomorrow.
Agree this would be ideal but that would require changes to the core.
Understood - I hope this can be improved in future versions, but for now I'm glad the extensibility allows you to get as far as we have. My remaining moans are really minor things