1 (15.05.2023 6m) Flashcards

1
Q

What are the ways to create scheduler? Give examples. Describe some setup options.

A
  1. Using an implementor of ISchedulerFactory.
// construct a scheduler factory using defaults
StdSchedulerFactory factory = new StdSchedulerFactory();

// get a scheduler
IScheduler scheduler = await factory.GetScheduler();
await scheduler.Start();

  1. Using SchedulerBuilder
var sched = await SchedulerBuilder.Create()
    // default max concurrency is 10
    .UseDefaultThreadPool(x => x.MaxConcurrency = 5)
    // this is the default 
    // .WithMisfireThreshold(TimeSpan.FromSeconds(60))
    .UsePersistentStore(x =>
    {
        // force job data map values to be considered as strings
        // prevents nasty surprises if object is accidentally serialized and then 
        // serialization format breaks, defaults to false
        x.UseProperties = true;
        x.UseClustering();
        x.UseSqlServer("my connection string");
        // this requires Quartz.Serialization.Json NuGet package
        x.UseJsonSerializer();
    })
    // job initialization plugin handles our xml reading, without it defaults are used
    // requires Quartz.Plugins NuGet package
    .UseXmlSchedulingConfiguration(x =>
    {
        x.Files = new[] { "~/quartz_jobs.xml" };
        // this is the default
        x.FailOnFileNotFound = true;
        // this is not the default
        x.FailOnSchedulingError = true;
    })
    .BuildScheduler();

await scheduler.Start();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Quartz.Net Scheduler?

A

Scheduler is a central concept in Quartz.Net.
It executes jobs according to given triggers.

Scheduler is responsible for process triggers and job execution when triggered. This way there are a bunch of methods allowing to add, remove, and list, pause, restart Jobs and Triggers

When Scheduler is instantiated, you can call its Start() or StartDelay() method in order to start triggers firing and consequent job execution.

Scheduler can be paused by calling Standby() method. The scheduler is not destroyed and can be re-started at any time.

When you don’t need the scheduler (and jobs execution) anymore you call Shutdown() method. You can’t call the Start() after this, because Shutdown() frees up all associated resources. The re-instantiation is required in order to proceed with job execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why do you need IJobDetail? How to get IJobDetail?

A

You can’t schedule IJob directly. For this, you must create IJobDetail.
To do this, JobBuilder is used.

// define the job and tie it to HelloJob class
// HelloJob must implement IJob
IJobDetail job = JobBuilder.Create< HelloJob >()
.WithIdentity(“myJob”, “group1”) // name “myJob”, group “group1”
.Build();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is trigger? Remember example how to use it.

A

Trigger is an object that describes a schedule of a job.

It means, that to make a job executable, you must define the schedule of the job by creating a trigger.

And then you can call the ScheduleJob() method of Scheduler providing job and trigger.

IJobDetail job = JobBuilder.Create< HelloJob >()
.WithIdentity(“myJob”, “group1”) // name “myJob”, group “group1”
.Build();

// Trigger the job to run now, and then every 40 seconds
ITrigger trigger = TriggerBuilder.Create()
    .WithIdentity("myTrigger", "group1")
    .StartNow()
    .WithSimpleSchedule(x => x
        .WithIntervalInSeconds(40)
        .RepeatForever())            
    .Build();
// Tell quartz to schedule the job using our trigger
await scheduler.ScheduleJob(job, trigger);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Name four available trigger schedule extension methods.

A

WithCalendarIntervalSchedule
WithCronSchedule
WithDailyTimeIntervalSchedule
WithSimpleSchedule

How well did you know this?
1
Not at all
2
3
4
5
Perfectly