Labels

slider

Recent

Navigation

What is Open-source quartz job scheduler system for .NET?

Open sourced jobs scheduling framework for .net, .net core, c#, ASP.Net etc
What is Open-source quartz job scheduler system for .NET

Introduction

After your journey on my previous articles such as ServiceStack, Data extraction, pc screen recording and many more, this article about Quart.Net is quite innovative for the developers which help the users for Job scheduling purpose throughout .Net programming job.

What are the main benefits of Quartz .Net?

Let’s have a view on the significant features of Quart.Net.

  • Compatible with Runtime Environments

Quartz.NET job scheduler system can run as a stand-alone program within the .NET virtual machine and can be entrenched easily within another free positioning application. Also, Quartz.NET can be implemented as a group of stand-alone programs along with load-balancing and fail-over abilities. This feature shows the effective compatibility with runtime environments.

  • Effective Triggers for Job Scheduling

Jobs are being scheduled to run when a preset Trigger applies. Here, the proper triggers need to be programmed which can satisfy the need of users for Job Scheduling purposes. Triggers can be developed with nearly any the amalgamation of the following commands:
    • at a particular moment of the day (to the few seconds)
    • on particular days of the week or month or year.
    • not on particular days ( Business holidays) listed within any registered Calendar
    • repeated for a given number of times set by the users
    • repeated endlessly
    • repeated until a particular time/date
    • repeated within a specific interval
Jobs are named by their users and can also be planned into some relevant named groups. Programming Triggers might also be named and placed into groups, for the purpose of easier accomplishment within the job scheduler. The significant point here is that Jobs can be added to the scheduler only once, but can be registered with more than one Trigger which is a really advantageous feature.

  • Job determination

The design of Quartz.NET comes with an IJobStore interface that can be put into practice to offer different methods for the storage of jobs. With the inclusion of AdoJobStore, all Triggers and Jobs are configured as "non-volatile" and are positioned in an RDBMS through ADO.NET.
Also, all Triggers and Jobs are stored in RAM with the help of the RAMJobStore and consequently do not carry on between program implementation - but this has the benefit of not desiring an external database.

  • Smart Job Execution

Jobs can be any type of .NET class that incorporates the simple IJob interface, leaving several possibilities for the performance of work Jobs. Also, Job class instances can be initiated by Quartz.NET job scheduler, or by the application's framework for a better programming experience.
When a Trigger is fired, the scheduler alerts nil or more .NET objects executing the TriggerListener and JobListener interfaces. Both listeners are also viewed after only the Job has executed.
As soon as Jobs are accomplished, they return a JobCompletionCode which notifies the scheduler about success or failure. The JobCompletionCode can also, command the scheduler of any proceedings it should take as per the success/fail code - such as an instance of repeat execution of the Job.

  • Clustering

    • Load balancing.
    • Fail-over.

  • Listeners & Plug-Ins

Please remember, these web applications can clutch the job scheduling events to check or manage job/trigger performance by incorporating multiple listener interfaces. The Plug-In approach can be utilized the added functionality to the Quartz.Net, like keeping a history of job scheduling executions, or loading job and definitions of the trigger from a file. Also, there are many "factory-built" plug-ins and numbers of listeners for the Quart.Net program.

How I can start with Quartz.Net?

Step #1: Download and Install

Either start downloading the zip file or move for the NuGet package at this beginning step. But, for your kind information, the NuGet package carries only the binaries required to run Quartz.NET, zip file possesses the source code, sample applications, and Quartz.NET server sample app.
NuGet Package couldn't have any simpler application than this. Just begin Visual Studio  application along with installed NuGet and link to Quartz package from package manager extension as follows:
  1. First, Right-click on the References of the project and select ‘Manage NuGet Packages...’
  2. Select Online category from the left side
  3. Search on the top right box by entering Quartz and press on enter.
  4. Select Quartz.NET from the search result page and press on install and installation is over.
Or To Install from NuGet, just type the following  Command-Line:

Install-Package Quartz

If you wish to add JSON Serialization, just add the ‘Quartz.Serialization.Json’ package in a similar way.

Step #2: Zip Archive

Once you got downloaded Quartz.NET, start unzipping it in your local folder (C-drive), get the Quartz.dll from the bin directory, and start using it.
But remember, the Quartz core library does not contain any firm binary needs. You can move for more dependencies when you select the JSON serialization package that needs JSON.NET. Here, the ‘Quartz.dll’ is mandatory along with the app binaries to run Quartz.NET fruitfully. So just add the ‘Quartz.dll’ as a reference to your Visual Studio project which will use them any time. Also, you can obtain these dlls from taken out the archive from the preset path ‘bin\your-target-framework-version\release\Quartz’.

Step #3: How to Configure?

Since the Quartz.NET is a big bit and a very configurable library, you need to configure the same in three ways (not reciprocally exclusive) to provide information on Quartz.NET configuration:
  • Programmatically  through rendering NameValueCollection the parameter to job scheduler unit
  • Through standard ‘YourApplication.exe.config’ configuration file utilizing quartz-element (whole .NET framework only) or appsettings.json (.NET Core for JSON use)
  • Through quartz. config file in the root directory of your application (functions both with .NET Core and full .NET Framework)

A simple Quartz application

To get up and running immediately a simple quartz.config looks something like this:

Never forget to set the ‘Copy to Output Directory’ on Visual Studio's file property pages to get value Copy always. Otherwise, the configuration will not be viewed if it's not in the development directory.

Summary of an above simple configuration

The above job  scheduler created by this configuration has the following features:
‘quartz.scheduler.instanceName’ - This name of the scheduler is "MyScheduler".
quartz.threadPool.maxConcurrency - Maximum 4 jobs can be run at the same time. You can increase or decrease
quartz.jobStore.type - All the information of Quartz, such as jobs and triggers, will be stored held in RAM instead of a database. Do you wish to store information in a database? It’s better to store information in RamJobStore. You can open up a completely new dimension by working with a database.

Sample Application-2

As of Quartz 3.0 your app will come to an end when no code is remained to execute after only the scheduler.Shutdown(), as there will be no active threads. You should block the exit of the application manually if you wish the job scheduler to keep running also after the Task. Delay and Shutdown have been implemented.
Now running the program doesn’t display anything. After, around 10 seconds, the scheduled program will terminate automatically. 

#Adding logging to console

You can configure LibLog for use of various logging frameworks under the hood; such as Log4Net, NLog, and Serilog.
While LibLog can’t find any other logging framework to be there, it will keep silent. You can configure a custom logger contributor that just logs to console display the output if you haven’t kept ready the logging framework set up yet.

#Trying out the application and adding jobs

Now we should get a lot more information when we start the application.

[12.51.10] [Info] Quartz.NET properties loaded from configuration file 'C:\QuartzSampleApp\quartz.config'
[12.51.10] [Info] Initialized Scheduler Signaller of type: Quartz.Core.SchedulerSignalerImpl
[12.51.10] [Info] Quartz Scheduler v.0.0.0.0 created.
[12.51.10] [Info] RAMJobStore initialized.
[12.51.10] [Info] Scheduler meta-data: Quartz Scheduler (v0.0.0.0) 'MyScheduler' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'Quartz.Core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'Quartz.Simpl.DefaultThreadPool' - with 3 threads.
  Using job-store 'Quartz.Simpl.RAMJobStore' - which does not support persistence. and is not clustered.

[12.51.10] [Info] Quartz scheduler 'MyScheduler' initialized
[12.51.10] [Info] Quartz scheduler version: 0.0.0.0
[12.51.10] [Info] Scheduler MyScheduler_$_NON_CLUSTERED started.
We need a simple test job to test the functionality, lets create HelloJob that outputs greetings to console.

To do something interesting, you need code just after Start() method, before the Task.Delay.

Now go have some fun exploring Quartz.NET! You can continue by reading the tutorial.

FAQ

Q.1 What is Quartz

Quartz is mainly known as a job scheduling system that can be incorporated with, or utilized alongside a virtually software system. 
From a Software Component View, we can define Quartz as a distributed and small .dll file that carries the entire core Quartz functionality. The main API (interface) is the Scheduler interface which facilitates simple operations like scheduling/unscheduling jobs, starting/ pausing/stopping/ the scheduler.

Q.2 Why not just use System.Timers.Timer?

Since, the .NET Framework possesses "built-in" timer capabilities, through the System.Timers.Timer class – no need to use Quartz rather than these standard characteristics.
Some more reasons are given below:
  1. Timers have no perseverance mechanism.
  2. Timers have inflexible scheduling (only can set start-time & repeat interval, not based on dates, time of day, etc.)
  3. Timers don’t have real management schemes - you have to write only your own mechanism to keep in mind, organize, and recover the tasks by name, etc. 
  4. Timers never use a thread-pool (it uses a single thread per timer)

Q.3 How many jobs a Quartz can run?

No limit. As per your requirement and RAM size, you can set the number of Job schedulers in Program.

Q.4 How can I control the instantiation of Jobs?

Through ‘Quartz.Spi.IJobFactory’ and ‘Quartz.IScheduler.JobFactory’ the property, you can fulfill.

Q.5 How a Job can be kept from being detached after it accomplishes?

The ‘JobDetail.Durable’ property needs to be set TRUE which instructs Quartz not to remove the Job when it turns into an "orphan" (when the Job no longer contains a Trigger referencing it).

Q.6 How do I keep a Job from firing at the same time as?

In Quartz.NET 2.x, just apply IJob and also embellish the job class with the [DisallowConcurrentExecution] attribute. 
In Quartz.NET 1.x, create the job class execute IStatefulJob rather than IJob. 

Q.7 How do I stop a Job that is presently executing?

In Quartz 1.x and 2x: Throughout the Quartz.IInterruptableJob interface, and the IScheduler.Interrupt(string, string) method, you can set the same
In Quartz 3.x: You can checkout ‘ IJobExecutionContext's CancellationToken.IsCancellationRequested’

Hope, the above content is informative. You can also go through other .net Articles, such as 

Share

Anjan kant

Outstanding journey in Microsoft Technologies (ASP.Net, C#, SQL Programming, WPF, Silverlight, WCF etc.), client side technologies AngularJS, KnockoutJS, Javascript, Ajax Calls, Json and Hybrid apps etc. I love to devote free time in writing, blogging, social networking and adventurous life

Post A Comment:

0 comments: