Skip to main content

CRON job in Windows Azure - Scheduler

Yesterday I realized that I have to run a task on Windows Azure every 30 minutes. The job is pretty simple; it has to retrieve new data from an endpoint. This is a perfect task for a CRON-base job.
The only problem with the current version of Windows Azure is that it doesn't have support for CRON jobs. People might say that we can have a timer and every 30 minutes we could run the given task. This is a good solution and it will work perfectly, but I wanted something different.
I didn’t want to create my own CRON-base job. I wanted something build-in in the system. I started to look around and I found an add-on for this. So, Windows Azure offers a Store for any company that want to offer different add-ons for Windows Azure. These add-ons can be very easily installed. If they are not free, the payment method is quite simple. Each month the Azure subscription will contain the cost of these add-ons. From my perspective this is a pretty simple and clean mechanism of payment.
Under the store I discovered the “Scheduler” add-on, offered by ADITI Cloud Services. This add-on gives us the possibility to create different jobs that are called at a specific time interval. We don’t need a timer, another machine or something similar.
How it works? It is based on normal HTTP requests that will be made automatically to your machine. Their servers will call your machines when a job needs to be executed. In this moment, they support only HTTP, without any kind of authentication. I expect in the near future to have support for authentication and HTTPS.
In this moment the service is free and you can execute around 5000 jobs per month for free. This mean that you can trigger a job every ~9 minutes.
Let’s see some code now. After you install the add-on from the Windows Azure Store, the “Scheduler” will generate a tenant id and a secret key. This will be used from your application when you will need to configure the jobs.
After this step, we need to install a NuGet package called “Aditi.Scheduler”. This will contain all the components that we need to be able to configure and use this add-on.
In our application we have to create an instance of “ScheduledTasks”. Using this instance we can create, modify or delete jobs.
ScheduledTasks scheduledTasks = new ScheduledTasks([tenantId], [secretKey]);

ScheduledTasks task = new TaskModel
    {
        Name = "MyFooJob",
        JobType = JobType.Webhook,
        CronExpression = "0 0/5 * 1/1 * ? *",
        Params = new Dictionary<string, object>
        {
            {"url", "http://foo.com/service1"}
        }
    };

scheduledTasks.CreateTask(task);
Each job can be changed, deleted and so on. What we should remember is to delete a job when we stop using it. Even if our solution will not be deployed anymore, the job will still be trigged each time. Because this solution is based on HTTP request, we need to expose a REST service from where we want to trigger our job.
A cool thing that we already have is the different type of jobs. We don’t have only web jobs but also jobs that use Service Bus Queue or Azure Queue. In this way we can listen to an Azure Queue from our application and our job will be triggered when a specific message is found in the queue. This feature can be used on worker roles that don’t have a HTTP endpoint exposed.
In conclusion I could say that this is a pretty interesting add-on that has a lot of potential.

Comments

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(...

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine: threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration: TeamCity .NET 4.51 EF 6.0.2 VS2013 It see...

Navigating Cloud Strategy after Azure Central US Region Outage

 Looking back, July 19, 2024, was challenging for customers using Microsoft Azure or Windows machines. Two major outages affected customers using CrowdStrike Falcon or Microsoft Azure computation resources in the Central US. These two outages affected many people and put many businesses on pause for a few hours or even days. The overlap of these two issues was a nightmare for travellers. In addition to blue screens in the airport terminals, they could not get additional information from the airport website, airline personnel, or the support line because they were affected by the outage in the Central US region or the CrowdStrike outage.   But what happened in reality? A faulty CrowdStrike update affected Windows computers globally, from airports and healthcare to small businesses, affecting over 8.5m computers. Even if the Falson Sensor software defect was identified and a fix deployed shortly after, the recovery took longer. In parallel with CrowdStrike, Microsoft provi...