All guidance I’ve been able to find, points to using:
Microsoft.Azure.Management.ResourceManager.Fluent
but that package has been deprecated and suggests this (from the nuget page):
If you are looking for the latest packages to interact with Azure resources, please use the following libraries:
Azure.ResourceManager
Azure.ResourceManager.Resources
After installing those packages plus Azure.ResourceManager.AppService, I can get close with this:
var webApp = client.GetResourceGroupResource(ResourceIdentifier.Parse("resId"));
var webSite = webApp.GetWebSite("siteName").Value;
var webjob = webSite.GetWebSiteWebJob("jobname");
(resId, siteName and jobname aren’t relevant for the question)
On the webSite object there is this:
webSite.Restart(); // also an Async version
But on the webjob, there is nothing I can see to kick off a restart. All of the following lack a restart option:
webjob.NotHere();
webjob.Value.NotHere();
webjob.value.Data.NotHere();
I feel like I’m missing something. How do I restart a webjob using the new nuget packages? Any guidance is greatly appreciated!
2
Answers
Figured out I was missing something simple. Webjobs can be triggered or continuous, only continuous may be stopped and started. So if the objective is to restart, I need to explicitly get only continuous webjobs, not simply 'webjobs'.
The above code becomes:
The key difference being, "GetWebSiteContinuousWebJob", which returns a "WebSiteContinuousWebJobResource", which has the required Start and Stop methods.
The
webSite.Restart()
method is used to restart the entire Azure Web App. If you want to restart a specific WebJob, you can use the Azure REST API to send an HTTP POST request.Even you have an option in portal. Go to the kudo and select process explorer and directly kill the webjob of the specific instance.
This method is effective for restarting web jobs that are set to run continuously. If you have triggered or scheduled web jobs, they may need to be manually triggered or scheduled again after the restart. check for the reference.