I have a job I'd like to run on my new Azure hosted web app. In the old pre-Azure days, I would create an .aspx page that did the job, then have some service that simply called the url (www.mysite.com/folder/myjob.aspx) on a schedule.
Is there a better way to do this with webjobs? Can I interact with the actual object model of my site or am I restricted to public URLs and the such?
I've heard I can write a full application (.exe) and host that, but I'm wondering what the advantage of that is?
There are a couple of ways to do this
Azure Worker Roles -Create a console application and then spin this cloud service executes the console app or process. https://azure.microsoft.com/en-us/documentation/articles/fundamentals-introduction-to-azure/
Azure Website Jobs - https://azure.microsoft.com/en-us/documentation/articles/web-sites-create-web-jobs/
I think website jobs is what you really are looking for. Build a little powershell or EXE of what you want doing then set it on a website job with a schedule. I don't think there is really much advantage either way, if you are already in the azure cloud this is just another service to leverage. We currently use both jobs and worker roles. Worker roles have the advantage of scaling out if needed.
Related
I have a saas web application using asp web api hosted in azure. I need to schedule some tasks to:
Generate monthly/yearly billing
Run recurring sql script
Send daily summary to users by email
Any recommendation or pointer on how i can do this? Should i create another app or can i host it inside my web api app?
If you want to have a reliable tasks scheduling wherein you can apply time interval depend on your choice, I recommend Quartz. Quartz allow to add/edit/delete/etc a scheduled task easily, manageable and no CPU overhead.
This is what Azure Web Jobs are for - running background tasks. It is a feature of the Azure Web App your Web API is running in. You can set it up as a scheduled job using the Azure Scheduler. How to do this is also in the link I provided.
I have an Azure Worker Role running in a Cloud Service. The worker is a wrapper around my custom library which runs code. When I make a change to my library I'd like to simple replace the old with the new. Currently I have to republish the entire Cloud Service project which takes time and seems like a wasted effort. I understand it might be necessary when I have multiple instances or other issues, but for now I'd like to simply copy my new dll to the service instead of publishing the entire project.
Is this possible?
After reading the documentation linked to by Ralf I found this:
If your app’s backend infrastructure is stable, but the web roles need
more frequent updating, you can use Web Deploy to update only a web
role in your project. This is handy when you don’t want to rebuild and
redeploy the backend worker roles, or if you have multiple web roles
and you want to update only one of the web roles.
later it restates :
Only web roles can be updated: Worker roles can’t be updated. In
addition, you can’t update the RoleEntryPoint in web role.cs.
For anyone wanting to update a web role this nugget is very important to remember:
The changes are made directly to the virtual machine where the web
role is running. If this virtual machine has to be recycled, the
changes are lost because the original package that you published is
used to recreate the virtual machine for the role. You must republish
your application to get the latest changes for the web role.
When you are developing and testing an Azure application, you can use Web Deploy to publish changes incrementally for your web roles.
More info:
https://msdn.microsoft.com/en-us/library/azure/ff683672.aspx
For webrole Web deployment could incrementally add the new file. If you Want not to enable web deploy you need to have remote Access enabled for the role, then you can connect to the instance and replace the .dll file.
Depending on the role you'll need to find IIS folder (in case of Webrole) or access "%ROLEROOT%\AppRoot" (in case of Worker Role).
You could need to restart the IIS instance in web role scenario. For worker role you'll need to kill WaWorkerHost, it will be restarted automatically
So my application is composed of a handful of separate .NET components that all run in Azure. To give you an idea of what's involved:
A main ASP.NET MVC5/Web API 2 REST service that runs as an Azure website (I think they renamed these to web apps?).
A SQL database that the main REST service uses.
Another internal Web API REST service that the main REST service talks to that runs as an Azure website.
An Azure storage table that the the internal Web API REST service uses.
3 scheduled jobs (just .NET exe's) that do work in the background and also talk to the main SQL database.
All that's running great in Azure right now. My problem is automating the deployment and configuration.
Right now it's all manual. I right-click and publish both web apps from Visual Studio. I build and FTP up the web jobs. The database and Azure storage already exist so I don't have to re-set them up.
But say something bad happens - a datacenter goes down or something. I'd like to be able spin up a new version of my app (with all those components) that is ready to go with minimal effort.
I'm pretty new to the world of Azure so I'm not sure where to start. What are my options?
You are looking to automating deployments in Azure. I recommend to use ElasticBox to solve it.
To achieve the automation you will need to create a box for every different service or component you need to deploy (a box is the abstraction unit that uses to define the installation and configuration of the deployment of a service or application in any cloud).
It's possible also to create boxes based on VM Instances, VM Roles, or Worker Roles and also automate the deploy of Microsoft SQL Servers. Let's say near every option offered by Azure.
Then with those boxes completed (that can be customized and reuse your legacy code from your previous manual installation), you can deploy the multiple vms with near no manual intervention, just one click or a command with some parameters.
A box includes the variables necessary for your deployment (you can set default values for those variables) and your legacy scripts (In this case probably PowerShell, but they could be bash, python, perl, java, or any other language)
When you deploy your boxes:
Creates a Cloud Service or VM in the location that you choose and with the Azure configuration that you preconfigured. It takes care of provision the vm in your Azure provider, or near any other cloud provider in the market.
Installs, configure files with your specified variables and execute your SQL or Web services that you have defined.
Other ways to interact with the service:
Jenkins' Plugin could be used to build a CI environment connecting your code updated or a Pull Request with automated deployments in Azure or any other public cloud.
Command line tool that enables to do VM deployments of your boxes and also you can manage your deployed vm instances with it.
Azure Resource Manager (ARM) is intended to solve exactly the issues you described.
The basic idea is that you use a JSON template to describe all your services. You can then give that template to ARM and it will create the services as defined in the template. If you want to make a change, instead of doing it imperatively (via powershell or manually in the portal) just update your template, pass it to ARM and it will make whatever changes are necessary to make the services match your template.
Some resources:
ARM talk at MS Ignite 2015
ARM template language reference
Quickstart templates on GitHub
Azure Resource Explorer - view ARM templates of existing resources
Resource Group Deployment Projects in Visual Studio
I think your looking for something to help you handel deploys to your windows Azure servers. If that is the case I recommend looking into Jenkins CI. There are many resources available online you can look into in terms of having Jenkins and Azure work together.
I have an ASP.NET MVC4 website running and now i need some sort of background task that is continously running. But is this even possible?
The MVC4 website is a sort of notifying system. Other websites can register a Callback URL on this website and this website should trigger that callback URL for a specified interval. So, for every hour for example.
Normally the code of my website only becomes active when I visit a page. But in order to make this work I need a way to have my ASP.NET website to run in the background continously. So it can do its checks and make an HTTP call when necessary.
It's important though that other websites can register their own Callback url through an http web request, and not through a socket.
Is something like this possible in an ASP.NET MVC web application? Or do I need a different approach?
Check this out: Easy Background Tasks in ASP.NET MVC
I do not prefer to run continuous jobs in asp.net because of these reasons.
You can use Windows Azure Scheduler for scheduling http requests for a particular URL.
Alternatively you can create a Windows service (example here)
You can also try console app and schedule it using Windows task schedule
Azure Worker Role is also a good option
I want to work with job scheduling and browsing on the internet I saw that Quartz.Net is a good option for it. Many blogs show that a windows service must be initialized and my question is: is it always necessary to start a windows service and embed it to run a job scheduler? Is there a way to run a job scheduler without using a windows service, I ask this because I have a access to a hosting that has only a web panel and I don't think it will let start a windows service.
Thanks for reading
Well, a alternative to writing a simple windows service, is to use the inbuilt windows task scheduler, if you have administrative permissions on the machine you would like to configure. To configure a task in Task Scheduler, have a look at the following Microsoft Article
Working with a windows service is very simple too, a good starting point is as shown below
Walkthrough: Creating a Windows Service Application in the Component Designer
I have worked on Quartz.NET and recommend it highly. The best resources that I used when working with Quartz are as given in the following SO Post.
Quartz can also be used in a ASP.NET web application
How to use Quartz.net with ASP.NET
Quartz.net setup in an asp.net website