1

I understand that you compile the Quartz solution into an exe that can run as a Windows Service. And that somehow this Quartz server runs jobs. What I don't get is, where do I put all my Job code that actually does the work? Like let's say I want my "job" to call a stored proc, or to call a web service every hour. Or what if I have native VB code I want to execute? (And I don't want to create yet another standalone VB app that gets called from the command line.) It wasn't obvious where all these types of job config would get stored, coded, configured.

Kane Jeeves
  • 475
  • 2
  • 9
  • 19

1 Answers1

1

I would suggest you to read the tutorials first.
You can find lot of useful information on Jay Vilalta's blog.

Getting Started With Quartz.Net: Part 1
Getting Started With Quartz.Net: Part 2
Getting Started With Quartz.Net: Part 3

and

Scheduling Jobs Programmatically in Quartz.Net 1.0

or

Scheduling Jobs Programmatically in Quartz.Net 2.0

and then you can have a look at the github code and try the examples which are very well documented.

UPDATE:

The server is the scheduler.
It's a windows service application which runs constantly and runs the job you've scheduled with a client application.
You can even write your own server (windows services), as I did, since I didn't want to use remoting to talk to that layer.

You can decide to schedule and run jobs in a console application (I wouldn't suggest that) with few lines of code:

class Program
{
    public static StdSchedulerFactory SchedulerFactory;
    public static IScheduler Scheduler;

    static void Main(string[] args)
    {
        SchedulerFactory = new StdSchedulerFactory();
        Scheduler = SchedulerFactory.GetScheduler();

        var simpleTrigger = TriggerBuilder.Create()
                 .WithIdentity("Trigger1", "GenericGroup")
                 .StartNow()
                 .WithSimpleSchedule(x => x.RepeatForever().WithIntervalInSeconds(5))
                 .Build();

        var simpleJob = JobBuilder.Create<SimpleJob>()
                                     .WithIdentity("simpleJob", "GenericGroup")
                                     .Build();

        Scheduler.ScheduleJob(simpleJob, simpleTrigger);

        Console.WriteLine("Scheduler started");

        Scheduler.Start();

        Console.WriteLine("Running jobs ...");

        Console.ReadLine();

        Scheduler.Shutdown(waitForJobsToComplete: false);

        Console.WriteLine("Shutdown scheduler!");

    }
}

This is the job:

public class SimpleJob : IJob
{
    public virtual void Execute(IJobExecutionContext context)
    {
        JobKey jobKey = context.JobDetail.Key;
        Console.WriteLine("{0} Executing job {1} ", DateTime.Now.ToString(), jobKey.Name);
    }
}

You can download a test project here (VerySimpleQuartzApp).

The application above does not store trigger/jobs information.

You can decide if you want to save the information of your jobs/trigger in a XML file as explained here and here.
Or you can store your jobs/triggers in a database so that the scheduler - usually a windows service - can read those info and run the jobs.

If you're looking for an example where you can communicate with the server (via remoting) and schedule a job and run it, this is the one.

There are a few open source projects (managers) which you can use to start/stop or schedule jobs. Read my answer here.

Community
  • 1
  • 1
LeftyX
  • 35,328
  • 21
  • 132
  • 193
  • Thanks, I read all that prior to posting. The only actual example I saw was how to run a separate EXE file from the command line, which is something I don't want to do. And so all the code examples...where do you put that code? In the Quartz solution itself? What about simple calls to a web service? Do I have to build an entire app just to call the service? It's these actual implementation details that I find missing in all the tutorials. – Kane Jeeves Jan 24 '13 at 12:53
  • Very helpful! I'm almost there. So I have the scheduler like you said. I can define schedules, jobs, etc. in a db somewhere using a client like you said. But where do I put the actual working code that IS the job? I don't see in the job xml anything that would tell the scheduler what exactly to run. Do I put DLLs somewhere? Also, what about a simple web service call every hour? Do I need a whole mini exe or dll for something that simple? – Kane Jeeves Jan 25 '13 at 12:52
  • You can integrate your scheduler where you want. I normally create jobs in a web app and run them in a service. the job (the one which inherits IJob) must be known by the client and the server and it executes your task (EX: call a web service) http://quartznet.sourceforge.net/tutorial/lesson_2.html – LeftyX Jan 25 '13 at 13:17
  • I see you can send in params to Jobs. Would it be a good strategy to create various "Do the Work" Job DLLs, each of which does one thing, like calls web svcs, executes SQL stored proc, etc. and just put those DLLs in a folder in the Quartz scheduler Win Svc solution? – Kane Jeeves Jan 25 '13 at 20:29