Using Quartz.NET in Orchard

Topics: Core, Customizing Orchard
Jun 27, 2013 at 3:48 AM
I need schedule to do some jobs in database recurrently, so I use Quartz.NET in Global.asax of Orchard.Web as follows:
protected void Application_Start() {
            RegisterRoutes(RouteTable.Routes);
            _starter = new Starter<IOrchardHost>(HostInitialization, HostBeginRequest, HostEndRequest);
            _starter.OnApplicationStart(this);

            ISchedulerFactory sf = new StdSchedulerFactory();

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

            var job = JobBuilder.Create<JobWorker>()
            .WithIdentity("job1", "group1")
            .Build();

            ITrigger trigger = TriggerBuilder.Create()
            .WithIdentity("trigger1", "group1")
            .StartAt(DateTime.Now)
            .WithCronSchedule("5 0/1 * * * ?")
            .Build();

            sched.ScheduleJob(job, trigger);
        }
And JobWorker class - is placed at the same level folder as Global.asax in Orchard.Web:
public class JobWorker : IJob, IDependency {
        private readonly ISchedulerService _schedulerService;

        public JobWorker (ISchedulerService schedulerService) {
            _schedulerService = schedulerService;
        }

        public void Execute(IJobExecutionContext context) {
            _schedulerService.ExecuteJob();
            
        }
    }
However, I've received results in debug output console as follows:
A first chance exception of type 'System.ArgumentException' occurred in Quartz.dll
A first chance exception of type 'Quartz.SchedulerException' occurred in Quartz.dll
A first chance exception of type 'Quartz.SchedulerException' occurred in Quartz.dll
The thread '<No Name>' (0x2278) has exited with code 0 (0x0).
The thread '<No Name>' (0x3368) has exited with code 0 (0x0).
The thread '<No Name>' (0x22a8) has exited with code 0 (0x0).
The thread '<No Name>' (0x2bc8) has exited with code 0 (0x0).
The thread '<No Name>' (0x290c) has exited with code 0 (0x0).
The thread '<No Name>' (0x9b8) has exited with code 0 (0x0).
The thread '<No Name>' (0x25cc) has exited with code 0 (0x0).
The thread '<No Name>' (0x2814) has exited with code 0 (0x0).
What should I do now ?
Thanks so much everyone
Developer
Jun 27, 2013 at 3:58 AM
Edited Jun 27, 2013 at 3:59 AM
It doesn't seem to be Orchard-related at all. Have you tried attaching a debugger?
A first chance exception of type 'System.ArgumentException' occurred in Quartz.dll
You probably provided a wrong argument somewhere.
Jun 27, 2013 at 5:31 AM
I have another web mvc 4 project - not Orchard - and it has worked OK. Code is the same as above. I think it caused by orchard !?
Developer
Jun 27, 2013 at 2:39 PM
Edited Jun 27, 2013 at 2:40 PM
Please attach the debugger, make sure you have thrown exceptions ticked in Debug -> Exceptions pane, and look at the stacktrace. I don't know Quartz.NET and this error clearly originates from there.
Jun 27, 2013 at 2:44 PM
I only need schedule some jobs recurrently and I've found that Orchard support IBackgroundTask interface that met my demand. Therefore I needn't use Quartz.NET anymore.
Anywhy, I appreciate what you've helped me @pszmyd
Developer
Jun 27, 2013 at 6:13 PM
Please do not cross-post.
Jun 27, 2013 at 6:28 PM
Sorry, I will learn a lesson of experience !
Developer
Jun 27, 2013 at 10:58 PM
No problem:)

Yeah, IBackgroundTask is definitely the extension point to leverage here.
I've also seen a module out there that allows to use CRON-like expressions for scheduling tasks. Not sure if it's in the gallery though.