Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are changes to my WebJob not being picked up when publishing the Web App?

I have an ASP.NET MVC Web App which is deployed to Azure. The solution within VS 2013 Pro has 3 projects:

  • the Web App project
  • a Webjob project
  • a Common project which stores code which is common to both the App and the Webjob.

The Webjob project was added to the main App project via the Add --> New Azure Webjob Project context menu, which actually adds a new project within the same solution, which is fine.

When I initially published the app to Azure, the Webjob was deployed too and all is working as expected. The Webjob runs on schedule once per day.

Now I've made some local changes to the Webjob and need those changes to be published. I follow the same process to deploy the App (rtClick main App --> Publish) which should also pick up changes to the Webjob, but the Preview pane is not picking up the changes and the changes are then subsequently not published to the Webjob.

Incidentally, any changes I make to the Common project are picked up successfully so looks like there is something weird about making changes and publishing Webjobs.

Has anyone come across this before?

like image 746
lee_mcmullen Avatar asked Jan 05 '16 09:01

lee_mcmullen


People also ask

How do I publish a Visual Studio WebJob?

NET Core WebJob to Azure App Service from Visual Studio uses the same tooling as publishing an ASP.NET Core app. In Solution Explorer, right-click the project and select Publish. In the Publish dialog box, select Azure for Target, and then select Next. Select Azure WebJobs for Specific target, and then select Next.

How do you monitor a WebJob?

You can monitor Web Jobs using 3rd party tool like CloudMonix or App Insights Web Tests(it is a part of Azure Monitor). With App Insights Web Tests you need Kudu Web Jobs API to get the current status of the web job, e.g. Call the Kudu API from your App Insights Web Tests.

When would you use a WebJob?

You can use the WebJobs feature of App Service to run a script or code in the context of an App Service web app. The WebJobs SDK is a framework designed for WebJobs that simplifies the code you write to respond to events in Azure services.


1 Answers

I've found the cause of the problem. It's actually very simple but also pretty frustrating.

When publishing the web app, you have the option to Remove additional files at destination. I have always left this checked because I don't like old files hanging around for no reason.

You also have the option to Exclude files from the App_Data folder which I also always leave checked so that files from App_Data are not deleted based on the remove configuration above. I then usually configure things like NLog log files, ELMAH xml files etc to go into App_Data safe in the knowledge that anything in there won't be deleted.

So the issue with Webjobs is that they're deployed into App_Data. So if the Exclude files from App_Data folder is checked then when the app is published, it's doing what it's told and ignoring App_Data and hence ignoring the changes to the Webjob.

So the simple solution is to uncheck this option and the Webjob is deployed successfully. However the issue now is that all other files in App_Data will be deleted (log files etc).

So you could uncheck the remove files config but that then potentially leaves other unwanted files lying around. Not ideal.

The other option is to leave the remove config checked, click the Preview button within the Publish dialog prior to publishing, then manually unchecking every file you don't want deleted. However the publish process fails if any of the files you want to keep are within sub-folders within App_Data e.g. App_Data/logs.

So the other option is to move all of the files within App_Data that you want to keep into the root of App_Data, then uncheck each of them within the Preview window prior to publishing. Not a huge deal when done once but becomes tedious when publishing lots of times.

I realise I could move log files etc to Azure storage, SQL DBs etc but what if it's the case that other files are in App_Data which need to be kept? App_Data isn't solely intended for Webjobs but using Webjobs creates a bit of an awkward situation if you also use App_Data for other things.

Be keen to know if I'm missing anything obvious here?

like image 66
lee_mcmullen Avatar answered Oct 12 '22 23:10

lee_mcmullen