How to setup Quartz.NET for scheduling Emails

后端 未结 2 893
有刺的猬
有刺的猬 2021-01-23 07:09

There are two solutions Quartz.server.2008.sln and quartz.2008.sln in the downloaded quartz.NET library. Now I have to setup recurring job. The

相关标签:
2条回答
  • 2021-01-23 07:21

    The quartz documentation does seem to assume that everyone knows the basics and is only looking for details.

    Hopefully the steps below, along with the Quartz documentation and samples, you'll be able to get your project started.

    Step 1: Open Windows Explorer to the ...\Quartz.NET-1.0.3\database\tables folder
    Step 2: Execute the script appropriate for your database
    Step 3: Open Windows Explorer to the ...\Quartz.NET-1.0.3\server\bin\3.5\console folder
    Step 4: Create a class library assembly and add a class that implements the IJob interface.
    Step 5: Edit the quartz.config file. Mine is below.

      ################################################################################
      # Added by Brad Bruce
      # please refer to http://quartznet.sourceforge.net/tutorial/lesson_9.html before making changes
      ################################################################################
      quartz.jobStore.type = Quartz.Impl.AdoJobStore.JobStoreTX, Quartz
      quartz.jobStore.driverDelegateType = Quartz.Impl.AdoJobStore.OracleDelegate, Quartz
      quartz.jobStore.tablePrefix = QRTZ_
      quartz.jobStore.dataSource = myDS
      quartz.dataSource.myDS.connectionString = Data Source=xe; User Id=quartz; Password=quartz;
      quartz.dataSource.myDS.provider = OracleODP-20
      quartz.jobStore.useProperties = true
    

    Step 6: Run the console server and verify that the dummy job is running
    Step 7: Copy the console project to a new project
    Step 8: Modify the console source to schedule the job via the Quartz API. You will be able to reuse this project to schedule other jobs.

    If they would only add a project to schedule and manage the jobs, I think Quartz.Net would really take off.

    0 讨论(0)
  • 2021-01-23 07:33

    I think you can create a windows service running in background. You can read the scheduleFromDatabase varaible from database and then pass it to Quartz.

    This is a small example from a console app:

        static void Main(string[] args)
        {
            ISchedulerFactory schedFact = new StdSchedulerFactory();
    
            IScheduler sched = schedFact.GetScheduler();
            sched.Start();
    
            JobDetail jobDetail = new JobDetail("myJob", null, typeof(HelloJob));
    
            //read this string from database
            string scheduleFromDatabase="0 11 16 ? * FRI,SUN";
    
            CronTrigger trigger = new CronTrigger("trigger1", null, "myJob",
                                                    null,scheduleFromDatabase );
    
            trigger.StartTimeUtc = DateTime.UtcNow;
            trigger.Name = "myTrigger";
            sched.ScheduleJob(jobDetail, trigger); 
        }
    
    public class HelloJob:IJob
    {
    
        public void Execute(JobExecutionContext context)
        {
            Console.WriteLine(DateTime.Now.ToString());
            //Call here your method!
        }
    }
    

    This can be useful:

    Quartz.NET server documentation

    0 讨论(0)
提交回复
热议问题