Skip to content

Quartz.net Plugin to report and monitor progress updates during the runtime of a job

License

Notifications You must be signed in to change notification settings

alanblack/Quartz.Plugin.JobProgress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quartz.Plugin.JobProgress

Quartz.Plugin.JobProgress is a plugin for Quartz.NET that allows you to report progress in long-running jobs and monitor progress updates using listeners.

Usage

  1. Configure your services in your application's entry point (e.g., Program.cs):
ConfigureServices(services =>
{
    services.AddQuartz(q =>
    {
        q.UseJobProgressReporting(options => {
            options.DefaultThreshold = 5;
        });
    });
});
  1. Create a JobProgressListener by extending the JobProgressListenerSupport class:
public class JobProgressListener : JobProgressListenerSupport
{
    public override string Name => "JobProgressListener";

    public override Task JobProgressWasChanged(IJobExecutionContext context, ProgressData progress, CancellationToken cancellationToken = default)
    {
        Console.WriteLine($"Program.JobProgressWasChanged {context.JobDetail.Key.Name} percent={progress.Progress}");
        return Task.CompletedTask;
    }
}
  1. Add the JobProgressListener to your scheduler:
var jobProgressListener = new JobProgressListener();
scheduler.ListenerManager.AddJobListener(jobProgressListener, GroupMatcher<JobKey>.AnyGroup());
  1. In your Job class, you can call the UpdateProgress method to report progress:
public class WorkerJob : IJob
{
    public async Task Execute(IJobExecutionContext context)
    {
        await Console.Out.WriteLineAsync($"WorkerJob STARTED"); 

        var progress = 0;
        while(!context.CancellationToken.IsCancellationRequested)
        {
            context.UpdateProgress(progress++, "Your data object. Put in whatever you like");
            await Task.Delay(1000);
        }
        await Console.Out.WriteLineAsync($"WorkerJob STOPPED");    
    }
}

License

This plugin is open-source and available under the MIT License. Feel free to use, modify, and distribute it according to the terms of the license. Contributions are also welcome!

About

Quartz.net Plugin to report and monitor progress updates during the runtime of a job

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages