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(

Azure AD and AWS Cognito side-by-side

In the last few weeks, I was involved in multiple opportunities on Microsoft Azure and Amazon, where we had to analyse AWS Cognito, Azure AD and other solutions that are available on the market. I decided to consolidate in one post all features and differences that I identified for both of them that we should need to take into account. Take into account that Azure AD is an identity and access management services well integrated with Microsoft stack. In comparison, AWS Cognito is just a user sign-up, sign-in and access control and nothing more. The focus is not on the main features, is more on small things that can make a difference when you want to decide where we want to store and manage our users.  This information might be useful in the future when we need to decide where we want to keep and manage our users.  Feature Azure AD (B2C, B2C) AWS Cognito Access token lifetime Default 1h – the value is configurable 1h – cannot be modified

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