-
Hi there, We have followed this tutorial to use a separate migration service to handle migrations when deployment is done through azd. var builder = DistributedApplication.CreateBuilder(args);
var sql = builder.AddSqlServer("sql")
.AddDatabase("sqldata");
builder.AddProject<Projects.SupportTicketApi_Api>("api")
.WithReference(sql);
builder.AddProject<Projects.SupportTicketApi_MigrationService>("migrations")
.WithReference(sql);
builder.Build().Run(); Local Azure deployment How can we prevent this from happening? Regards, Tom |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Hi @Fazer01 |
Beta Was this translation helpful? Give feedback.
-
Hey @Fazer01 , It sounds like the migration service container is being restarted repeatedly because the Azure Container Apps environment is treating it like a long-running service, rather than a "run-once-and-done" kind of job. This is probably because Azure Container Apps assumes that the container should be continuously running, but that’s not what you want for a migration service. Here’s how you can fix it: 1. Use a "Job" Instead of a Container AppAzure Container Apps recently introduced job support that is specifically designed for tasks like running migrations, one-off scripts, etc. Instead of running your migration service as a standard container, you can configure it to run as a job. This will ensure it only runs once when deployed, and doesn’t keep restarting. You can configure a scheduled job with a cron schedule or make it a run-once job with a manual trigger. Here’s a quick guide on how to create a run-once job:
This makes sure that the migration service runs just once when needed and doesn't automatically restart. 2. Shutting Down the Container GracefullyIf you want to stick with the current container setup, you could add logic to shut the container down after migrations are done. But the issue here is that the container infrastructure might still restart it after some time. So, another option would be to tweak the container’s
3. Azure Logic:You can also modify the logic of the container app by setting its replica settings to avoid constant restarts. For example, you can change the replica settings in Azure so that it only attempts to run a single instance, or set it up so that it doesn’t automatically restart unless there’s a failure. 4. Cron Trigger or Event-Driven Jobs:You can also schedule the migration service as an event-driven job if you want to make it run only on certain conditions, like a deployment event or a specific cron schedule. The best solution is to treat your migration service as a run-once job or configure Azure to properly recognize it as such. That will stop it from restarting and running migrations endlessly. Hope this helps! Let me know if you have more questions. Cheers |
Beta Was this translation helpful? Give feedback.
-
I have the same issue. I followed the Official Example and faced the issue. It is especially annoying because it is quite expensive. In fact I just realized the issue because the migration service has enormous cost compare to the other services. I think - as a workaround - I just let it running instead of stopping it. That is cheaper .... |
Beta Was this translation helpful? Give feedback.
Letting it run is the right workaround for now. There's no native support for container job as yet.