Michael Glass
Michael Glass

Reputation: 482

Quartz.NET implementation doesn't jive with tutorials

I attempted to implement a very simple Quartz.net implementation using this tutorial

using Quartz;
using Quartz.Impl;

// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();

// get a scheduler
IScheduler sched = schedFact.GetScheduler();
sched.Start();

// construct job info
JobDetail jobDetail = new JobDetail("myJob", null, typeof(HelloJob));
// fire every hour
Trigger trigger = TriggerUtils.MakeHourlyTrigger();
// start on the next even hour
trigger.StartTimeUtc = TriggerUtils.GetEvenHourDate(DateTime.UtcNow);  
trigger.Name = "myTrigger";
sched.ScheduleJob(jobDetail, trigger);

The problem I am running into is (for example) MakeHourlyTrigger is not available in the Intellisense, and gives me the error

Quartz.TriggerUtils does not contain a definition for 'MakeHourlyTrigger'.

I get errors on types such as JobDetail:

"The type or namespace name 'JobDetail' could not be found (are you missing a using directive or an assembly reference?)"

Maybe I'm tired and missing something stupid and easy... I hope that's the case. All of the examples I have seen on the Internets say that I should be using Quartz and using Quartz.Impl. Please tell me that I'm just missing something easy...

Upvotes: 29

Views: 6351

Answers (3)

Pure.Krome
Pure.Krome

Reputation: 86957

The documentation is aimed at the 1.0 API. Things have now changed, and yes, they are breaking changes.

Check this official migration page out. You might find some solutions in there.

Upvotes: 33

Colin
Colin

Reputation: 2011

I know this isn't the right place. I should edit the original Wiki blah blah blah. I'm trying to do 31 hours of work, in my evenings, by Friday. So here goes.

Lesson 1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
using Quartz.Impl;

namespace QuartzNetTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // construct a scheduler factory
            ISchedulerFactory schedFact = new StdSchedulerFactory();

            // get a scheduler
            IScheduler sched = schedFact.GetScheduler();
            sched.Start();

            // construct job info
            IJobDetail jobDetail = JobBuilder.Create<HelloJob>()
                .WithIdentity("myJob")
                .Build();
            ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity("myTrigger")
                // fire every hour
                .WithSimpleSchedule(x => x.WithIntervalInHours(1).RepeatForever())
                // start on the next even hour
                .StartAt(DateBuilder.FutureDate(1, IntervalUnit.Hour))
                .Build();

            sched.ScheduleJob(jobDetail, trigger);
        }
    }

    class HelloJob : Quartz.IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            Debug.WriteLine("Hello at " + DateTime.Now.ToString());
        }
    }

}

Upvotes: 11

Marko Lahma
Marko Lahma

Reputation: 6884

I'm pleased to announce that Quartz.NET's web site has been successfully migrated to GitHub Pages. It should be now easier for community contribute fixes and enhancements.

The tutorial is (finally) updated to include 2.x changes:

http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/index.html

Site is written in Markdown and can be updated with pull requests via GitHub:

https://github.com/quartznet/quartznet/tree/gh-pages

Upvotes: 3

Related Questions