Azure WebJob running in WebApp without a JobSchedule/JobCollection - deploy with template - azure

Right. So this article: https://azure.microsoft.com/en-us/documentation/articles/web-sites-create-web-jobs/ mentions that you can "You can run programs or scripts in WebJobs in your App Service web app in three ways: on demand, continuously, or on a schedule. There is no additional cost to use WebJobs."
Which is great, the free-alternative is a Scheduler Job Collection
with a job, but you're limited to running it every hour. So being able to run the webjob as part of the webapp, and on a higher frequency is what we need.
However, I'm really struggling to find any way of automating this process. Using the Azure portal to add a web job works fine - but the "automation script" generation tool doesn't generate a json file which includes anything about the webjob - so we'd always have to manually create it.
There are examples of custom templates for automating the creation of webjobs - but they all create said webjob as part of a Scheduler Job Collection, where we are limited to the hourly execution.
To summarise: I'm looking for a way of automating the creation of a webjob, linked to a web-app (such that it doesn't incur extra costs).
Any help would be much appreciated.

WebJobs are deployed by folder convention (as described here), so deploying a WebJob is no different from deploying a Web App. It's simply a matter of getting the files in the right place.
Specifically, triggered WebJobs (manual or scheduled) go under site\wwwroot\app_data\jobs\triggered\{job name} and continuous WebJobs go under site\wwwroot\app_data\jobs\continuous\{job name}.

Related

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.

How can I configure an Azure WebJob to run from a git deployed exe, rather than from an upload?

I have a deployment process that places everything needed within a repository which my azure AppService is already configured to pull from.
This deployment process is fully automated and works well.
I would like to amend this deployment process to include one or more console applications which would then be configured to be run as WebJobs, either when triggered, or on a continuous basis.
However the configuration for webjobs appears to want me to upload the .exe during configuration, rather than point at a pre-existing .exe.
This seems less than optimal, because it suggests that I'll have to reupload each time said console app changes.
It would be far more convenient to be able to point to a known location within the AppService which contained the full deployment of the WebJob console App.
Is there a way to achieve this?
As I know, the deployment process you want couldn't be done. No matter on which way WebJob is deployed, Job is copied to the file system on the Kudu in essence. And WebJob is a function depending on Web App Service, so the deployment couldn't be processed as a whole. You could read the Wiki.
From your description, I suggest you using Azure Functions. You also could use TimeTrigger、BlobTrigger、HTTPTrigger etc. You could write just the code you need for the problem at hand, without worrying about a whole application or the infrastructure to run it.
If you still have questions, please let me know.

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.

How to deploy a webjob through CI in VSO with vNext

I'm trying to deploy a scheduled webjob through CI and vNext tasks in VSO.
I followed the steps in the following tutorial to deploy a webjob along with a web app ("Enable automatic deployment with a web project"):
https://azure.microsoft.com/en-us/documentation/articles/websites-dotnet-deploy-webjobs/
I succeeded partially: the webjob gets deployed along with the web application. However, it is marked as On Demand instead of Scheduled (or whatever the proper status is). I can run the webjob manually and it runs just fine. I checked the files webjob-publish-settings.json (in the webjob) and webjobs-list.json (in the web app) and they seem to be alright, judging from the tutorial.
Am I missing anything? Thank you.
You can use the cron expression to create the webjob scheduler if your app is running in Basic or High mode. Refer to this link for details: Create a scheduled WebJob using a CRON expression
Otherwise, you need to enable continues delivery of Azure Webjobs.
More reference: Deploy your WebJobs projects with your Azure website using continuous delivery

Modify scheduling on Azure WebJob

Like many others I am enthusiastic about the lightweight WebJobs that can so easily be added to Azure Websites.
But I assumed one of the advantages with WebJobs was to easily modify the scheduling. When I tried I was surprised that there seems to be no way to do that. A deployed WebJob seems to be stuck with the initial scheduling.
Do I need to deploy new WebJobs just to modify the scheduling?
To change the schedule, or to Modify the CRON value just use the App Service Editor to modify the WWWROOT/App_Data/jobs/triggered/YOUR_WEBJOB_NAME/settings.job file;
By the time of writing, App Service Editor is still in preview but it
will work.
In the settings.job file amend the schedule in CRON value and will be reflected in the App's Web Job Dashboard.
The App Service Editor is available in App Service > Development Tools
App Service Editor (Preview)
I finally found it.
Scheduled WebJobs turn up under Scheduler in the main bar.
The Save button is not visible until you actually make a change.

Resources