Scheduled tasks on the web

Asked

Viewed 1,474 times

4

In Google Inbox allows the creation of reminders and allows you to postpone them to a certain date and time. The reminder is then taken from the main screen and when this exact date and time comes back there.

Thus, the system agenda a task for a date and time and when this date and time comes it executes what was scheduled.

I thought this would be impossible on the web for the following reason: as I know an application hosted on a web server (whether a website, an API, or something else) only executes something when there is a request. Thus, the application expects a request, when it receives it executes what was requested and again becomes idle.

In this case I quoted from Inbox is not what happens. The scheduled date and time comes and the system performs a task without requiring a request for it. Nor is it saying that you need to client connected because from what I realized I think without any client connected it also makes.

How can I do this kind of thing in an ASP.NET environment? I don’t say with IIS necessarily, because now with ASP.NET 5 the hosting options will increase a lot. Is there a way to have this application feature perform a particular scheduled task without relying on requests? If it exists, how does it work?

  • You can have a program running on the server that performs the tasks. This program can run based on a period of time or some event. I use 2 solutions for this purpose, the Webjob by Azure and Hangfire. Webjobs allows you to run an executable based on a time or event in Queue or blob. Hangfire is more limited but works great for events triggered by your site (although it works outside of Asp.net as well).

  • @Does Leo Hangfire work smoothly on Azure’s vm ? or is there incompatibility because of webjobs ? I need a background manager, I thought about webjobs, for using Zure, but Hangfire seems more flexible

  • @Rod, I use it for more than 6 months on a website on Zure and it works 100%, never gave any problem. Go without fear :D

  • @Rod, I’ve never used Hangfire, so I can’t tell if everything it offers, Web Jobs also offers. But you have another option too which are cloud services. In them you build N-Tier applications where you can add layers of background processing using the worker roles and layers containing websites or web roles. Do a little research on that, maybe it’ll help you.

1 answer

6


Essentially the same way you would in a task no web. It is the same as what you do on your computer. It can be the Windows task scheduler, the cron existing in Linux and similar distributions, or any other scheduling software. The application running on the server is an application like any other.

Simple solution

I think the ideal is to create a separate application from the rest of the application web itself. In it you put what needs to be executed in background at regular times and only serving what will be run on the server. In theory you can use any technology for this. You don’t necessarily need to be connected to ASP.Net, even if this is the technology you use in the rest of the solution. So it doesn’t mix with the application that talks directly to the customer. In some cases this can give more power avoiding security issues. Imagine this scheduled running application needs high privilege and is bundled with what the HTTP server runs. Dangerous, no?

Ready-made solutions

Of course, these schedulers need permission to use them. Not all hosting has this at their disposal.

  • Thanks @bigown, what you have in Scott Hanselman’s article is what I really needed, plus I finally discovered the usefulness of Worker Role in Azure. What you spoke of creating a separate application from the web application is equivalent to separating Worker Role and Web Role from Azure’s Cloud Services?

  • 1

    I don’t know the details of this technology, so I can’t do an assessment. You can say that in a way yes, at least the goal is the same but the way of doing and the capacity of each is quite different. What I said is to do something trivial independent of technology. Unless you have some reason to use something else is always the way I follow.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.