Azure WebJob running old code - azure

We have a bug in our WebJob running in our live environment, I have identified the bug and fixed it, this I can verify in our Dev-environment. I published my WebJob as a "Azure WebJob" to our live environment but the bug i still present. To add to the confusion the bug now just occurs sometimes. So for some reason the old code is running somewhere sometimes.
Can someone please help me understand this?

I had a similar problem. We deploy using a stage environment in Azure and it turned out that the "old" WebJobs (running code with an old version of the entity framework model) where still running on the queue. These jobs where then fetching messages and consuming them. To add to the problem the exception was consumed in a try catch and the status of the WebJob was success.
Check if you have a stage environment (add -stage to the Webapp name) and if so go in to the Azure management portal and stop them.
Note, it is not enough to stop the Webapp, you must stop the WebJobs directly. This is done (in the new portal) under Settings->WebJobs and then right-clicking on the webjobs name selecting stop.

I spent ages looking into this problem. Turns out I had the web job project running in a console on my PC at work! No matter what I did on Azure the presence of this exe running and using the same storage for the web jobs meant that the old code running on my work PC picked up the jobs before Azure did. Easy fix: just make sure no exes are running outside of Azure!

In our case the web app was published to physical path /site/www instead of the default /site/wwwroot, because of this the Azure web portal interface adds the WebJobs to folder /site/jobs, but the webdeploy via VS or Azure are still trying to publish the webjobs inside the /site/www.
More details at Publishing WebJobs with Azure Pipelines

Related

Azure Devops Pipeline returning: 'Failed to deploy web package to App Service. Internal Server Error (CODE: 500)'

I am trying to use Azure DevOps pipelines to build a .NET 5 (Core) web app and deploy it to my Azure app service. I can't find any complete examples in the documentation that achieve this so I'm following this:
https://github.com/shahedc/NetLearnerApp/blob/main/azure-pipelines.yml.txt
However, the Azure deploy task keeps returning this vague error:
In my Azure portal I only get this error:
I am assuming the issue is in my pipeline because deployment works when I deploy it directly from the Deployment Center in the Azure portal. Here are the details for the 3 relevant tasks my pipeline:
I found the solution. It turns out the issue was not in the pipeline, but was caused by a Git connection to the app service I had previously set up in the Azure Deployment Center. Even though I disconnected/removed this Git connection, there was somehow still a residual file left over in Azure that was causing the error. I deleted the 'deployments' folder in Kudu (pictured below) and the pipeline started working as expected.
Getting to the above pictured view:
Navigate to your Azure Function project
Search for Advanced Tools
Open PowerShell
Check if you have disk space available.
Yesterday we started getting this error, even if we tried to re-deploy packages that were successfully deployed just an hour before. Our system guys checked and found out that we reached the space limit and that it was time to upgrade.
P.S. I know that this was answered a long time ago. I am just sharing the solution that was not mentioned here and that worked for us.
think what Dan Beaulieu said in above answers is correct, but one thing to add, in my case, after deleting the deployments folder, remember to restart the app service/web app, which will make it take effect.

Error "Web Deploy cannot modify the file on the destination because it is locked by an external process" in Octopus deploy

We are deploying into azure using Octopus deploy. We are using it since more than a year, and suddenly we started (about 3 weeks ago) to get errors on few deployments.
Microsoft.Web.Deployment.DeploymentDetailedClientServerException: Web Deploy cannot modify the file 'msvcr120.dll' on the destination because it is locked by an external process. In order to allow the publish operation to succeed, you may need to either restart your application to release the lock, or use the AppOffline rule handler for .Net applications on your next publish attempt. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE
We have the webapp running and always on and we have the app setting 'MSDEPLOY_RENAME_LOCKED_FILES' to 1 that in theory prevents this.
Does anyone knows if something was changed in azure or octopus?
There are a number of reasons files may be locked during deployment. You should be able to get an idea of what may be locking files by using the kudu process explorer, which you can access using the url {yoursite}.scm.azurewebsites.net.
In order to avoid the locking issue altogether, you could make use of slots to achieve a zero downtime deployment if that's an option for you. In this case you could stop the site or enable App Offline which should unlock any files and allow the deployment to succeed after which a slot swap will make the deployment live. App Offline is preferred over using MSDEPLOY_RENAME_LOCKED_FILES, but will take the application offline during the deployment. Octopus also has support for this as an option on the Deploy an Azure Web App step itself, so may be worth a try even without slots.
You can use custom pre/post deployment scripts as part of your Deploy an Azure Web App to make use of the Stop-AzureRmWebAppSlot, Start-AzureRmWebAppSlot and Switch-AzureRmWebAppSlot Powershell commands Azure commandlets to achieve the above.
An alternative may be to use zip deployments, however, the Deploy an Azure Web App Octopus step doesn't have first class support for this quite yet. It can still be achieved using a Run an Azure PowerShell Script along with a package references if this is what you are wanting to do.

Azure WebJobs get deleted each time I redeploy?

Are Azure WebJobs get deleted each time when I redeploy? I found those WebJobs mysterious disappeared, so I guess maybe it's because I redeployed my app but didn't go to Azure portal to re set WebJobs again.
If that's the case, it is really a trouble to re set WebJobs again and again. Is there a way to automate this?
I deploy from Visual Studio. I read somewhere saying I can put my WebJobs (e.g. xxx.ps1) under App_Data/jobs/continuous/, and then whenever I deploy, the WebJobs will be deployed automatically. I did that, but I didn't see those WebJobs in my Azure portal.
See https://learn.microsoft.com/en-us/azure/app-service-web/websites-dotnet-deploy-webjobs for instructions on how to add WebJobs to your Web App from VS. Note that you don't need to worry about the App_Data/jobs/continuous folder, as that's taken care of by VS deployment.
Note that this is supported for ASP.NET but not yet for ASP.NET Core.

Azure WebApp: cannot modify file even though service is stopped

I am trying to deploy my app to an Azure WebApp slot but it seems that the file (Microsoft.Data.Edm.dll) it is trying to update is locked even though I have manually stopped the WebApp. I got the following error while deploying my app.
Web deployment task failed. (Web Deploy cannot modify the file 'Microsoft.Data.Edm.dll' on the destination because it is locked by an external process. In order to allow the publish operation to succeed, you may need to either restart your application to release the lock, or use the AppOffline rule handler for .Net applications on your next publish attempt. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE.)
I tried on both VSTS web deploy task and manual deploy from Visual Studio, it returns me the same error message. I tried restarting the WebApp, setting the COR_ENABLE_PROFILING = 0 then 1 too but again, same error. The last resort that I didn't try is delete the WebApp and recreate again.. but i would like to know if there are other suggestions first before I do this desperate measure.
Thank you in advanced.
Restarting works better, stop just stops the http listener, restart restarts the running proces
Please try to use Resources explorer portal to full stop your web app. In this way, we can delete some locked files via FTP without anything running. For more details about how to full stop your web app, please refer to this article
As of time of this writing, if you are using Azure DevOps (VSTS) to deploy your application, you can select "Run From Package" in the "Azure App Service Deploy" task/step - this is available in version 4 of the task, under the "Additional Deployment Options" node.
This deployment option eliminates file locking issues as it provides atomicity, in that the application is pointed to the new zip file rather than deploying a bunch of loose files under wwwroot, some of which may be locked.
It provides you with a number of other benefits that you can read about it if you search and read about the feature.
HTH

Octopus deployed continuous WebJob not running simultaneously in two locations

I have a continuous webjob that needs to run two webapps in two locations on a TimerTrigger. When I deploy the webjob from Visual Studio to both locations everything works well and both webjobs run at the same time.
Now I'm ready to start deploying this with Octopus-Deploy. I have successfully created a plan with two steps that does that and puts the assemblies in the correct location under the web apps (app_data\jobs\continuous\{jobname}) in Azure. The problem is that only one webjob executes its job at a time even though both webjobs have a status of Running. If I stop and start the one that's executing, the other webjob starts executing its job while the one I turned off/on has a status of running, but doesn't ever execute its job. Also, if I redeploy just one of them from visual studio, they both execute their jobs at both locations again.
I'm not doing anything with Singletons and have actually tried turning it off by using a 'settings.job' file with {is_singleton: false}. Is there something Octopus is doing with the package that makes Azure think the webjob is a singleton?
My guess is that the issue is caused by using the same storage account and host id for both of the apps that you deployed. When you do that, the WebJobs SDK views it as a single Web App that has been scaled out to two instances, and makes sure the timer is only run on one of them.
The simplest solution is to use a different storage account for each app.

Resources