Scheduled Tasks for Web Applications

社会主义新天地 提交于 2019-12-23 13:58:08

问题


What are the different approaches for creating scheduled tasks for web applications, with or without a separate web/desktop application?


回答1:


If we're talking Microsoft platform, then I'd always develop a separate Windows Service to handle such batch tasks.

You can always reference the same assemblies that are being used by your web application to avoid any nasty code duplication.




回答2:


Jeff discussed this on the Stack Overflow blog - http://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/

Basically, Jeff proposed using the CacheItemRemovedCallback as a timer for calling certain tasks.

I personally believe that automated tasks should be handled as a service, a Windows scheduled task, or a job in SQL Server.

Under Linux, checkout cron.




回答3:


I think Stack Overflow itself is using an ApplicationCache expiration to run background code at intervals.




回答4:


If you're on a Linux host, you'll almost certainly be using cron.




回答5:


Under linux you can use cron jobs (http://www.unixgeeks.org/security/newbie/unix/cron-1.html) to schedule tasks.

Use URL fetchers like wget or curl to make HTTP GET requests.

Secure your URLs with authentication so that no one can execute the tasks without knowing the user/password.




回答6:


I think Windows' built-in Task Scheduler is the suggested tool for this job. That requires an outside application.




回答7:


This may or may not be what you're looking for, but read this article, "Simulate a Windows Service using ASP.NET to run scheduled jobs". I think StackOverflow may use this method or it was at least talked about using it.




回答8:


A very simple method that we've used where I work is this:

  1. Set up a webservice/web method that executes the task. This webservice can be secured with username/pass if desired.
  2. Create a console app that calls this web service. If desired, you can have the console app send parameters and/or get back some sort of metrics for output to the console or external logging.
  3. Schedule this executable in the task scheduler of choice.

It's not pretty, but it is simple and reliable. Since the console app is essentially just a heartbeat to tell the app to go do its work, it does not need to share any libraries with the application. Another plus of this methodology is that it's fairly trivial to kick off manually when needed.




回答9:


Use URL fetchers like wget or curl to make HTTP GET requests.

Secure your URLs with authentication so that no one can execute the tasks without knowing the user/password.

You can also tell cron to run php scripts directly, for example. And you can set the permissions on the PHP file to prevent other people accessing them or better yet, don't have these utility scripts in a web accessible directory...




回答10:


Java and Spring -- Use quartz. Very nice and reliable -- http://static.springframework.org/spring/docs/1.2.x/reference/scheduling.html




回答11:


I think there are easier ways than using cron (Linux) or Task Scheduler (Windows). You can build this into your web-app using: (a) quartz scheduler,

or if you don't want to integrate another 3rd party library into your application: (b) create a thread on startup which uses the standard Java 'java.util.Timer' class to run your tasks.



来源:https://stackoverflow.com/questions/23382/scheduled-tasks-for-web-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!