开发者

Is it possible to use Quartz.Net with Spring.Net to create jobs in MS SQL DB with scheduled time

I am creating GUI interface in asp.net in which users will specify a time to schedule and开发者_如何学JAVA a job which will run at sometime in the future.

The job in my application is an instance of a Person class (given below). At a specified time, I want to run the "submit()" method of the created person instance.

e.g.

public class Person
{
  string User {get;set;}
  public void Submit()
  {
     //create a text file with User entry

  }
}

Now in MS SQL, I have a Jobs table. Jobs table has ScheduledTime (DateTime), JobDetail (XML) columns (where JobDetail column stores serialized version of Person object e.g. <Person User="TestUser"></Person>, Scheduled time: 2/2/10 12:12:11

I am aware that Quartz.Net can run jobs at their scheduled time. But I don't know how to use Quartz.Net with Spring.Net to pick up the jobs from DB and run them at their scheduled time?

Is it possible? If so can you please guide?


There are two separate components you'll need to implement. The trigger and something that polls for jobs to run. Based on your table structure so far it sounds like you want jobs that only run once and if not you'll need to add a cron expression column and create CronTrigger objects.

For polling for jobs to run you can find details on how to use Spring timer here: http://static.springsource.org/spring/docs/1.2.9/reference/scheduling.html

An alternative to Spring is implementing your poller in the database. For example, creating an SQL Server schedule job, the approach we went with. The downside is that you need to design it to pickup jobs missed when the database server is down.

Database approach details

This design assumes only run once schedules (to add recurring you need to add a cron translation step) and it assumes that the work the schedule does can get kicked off by the database. Spring is a better solution if you can only do that programatically.

  1. add a column 'processed' to your jobs table
  2. create a stored proc that runs every minute (or whatever)
  3. that procedure looks for any jobs in the past not marked as processed, kicks them off and then marks them as done

Related:

How do I configure Quartz.NET host with Spring.NET

Running a Job only once Using Quartz

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜