liveBook · Manning

Workflow job

As explained in ASP.NET Core in Action, 3e

A Quartz.NET job is a task whose executable logic is defined by an implementation of IJob.

A Quartz.NET job is a background task whose executable logic is defined by a class implementing IJob. The job contains the work to perform; Quartz.NET schedules and runs it in the background. section 34.3 section 34.3.1

A workflow job works with several Quartz.NET components:

  • The job implementation defines the task logic. section 34.3.1
  • Triggers determine when the job runs, such as every five minutes or on a monthly schedule. section 34.3
  • The job factory creates job instances, using the dependency-injection container when configured. section 34.3 section 34.3.1
  • The Quartz.NET hosted service starts the scheduler with the application and can wait for running jobs to finish during shutdown. section 34.3.1

A worker-service job setup

Install Quartz.Extensions.Hosting, register Quartz.NET with the Microsoft dependency-injection job factory, and add its hosted service. The scheduler then starts with the application; without registered jobs and triggers, it has nothing to schedule. section 34.3.1

Listing 34.10 Configuring Quartz.NET
using Quartz;
 
IHost host = Host.CreateDefaultBuilder(args)
    .ConfigureServices((hostContext, services) =>            #1
    {
        services.AddQuartz(q =>                              #2
        {
            q. UseMicrosoftDependencyInjectionJobFactory();  #3
        });
 
        services.AddQuartzHostedService(                     #4
            q => q.WaitForJobsToComplete = true);            #4
    })
    .Build();
host.Run();

Shows the minimal host configuration that registers Quartz.NET and starts its scheduler as a hosted service. section 34.3.1

When multiple application instances must share jobs, Quartz.NET can persist its configuration in a database and use clustering so only one instance handles a trigger at a time. section 34.3.3

How ASP.NET Core in Action, 3e covers it

How deep it goes
Defines IJob implementations and surrounding scheduler configuration, while leaving application-specific task logic to the job.
Examples
Uses a scheduled exchange-rate downloader and a Quartz.NET worker-service host configuration.
What it assumes
Assumes a .NET application and introduces job scheduling through the generic host and dependency injection.
What you can do after
Apply it via Quartz.NET to define, schedule, host, and coordinate background jobs.
How it connects
Connects jobs with IJob, triggers, job factories, dependency injection, IHostedService, and clustering.

Also explained in

Compare how 2 books explain workflow job →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.